From 7f1e2ded0ac8b756347a1a3a3165f1a48fcdaa7a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 21 Dec 2014 12:46:42 +0300 Subject: Save char sex in db. --- src/char/char.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/char/char.c b/src/char/char.c index b18beed60..698832bfb 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -453,16 +453,31 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) (p->head_mid != cp->head_mid) || (p->head_bottom != cp->head_bottom) || (p->delete_date != cp->delete_date) || (p->rename != cp->rename) || (p->slotchange != cp->slotchange) || (p->robe != cp->robe) || (p->show_equip != cp->show_equip) || (p->allow_party != cp->allow_party) || (p->font != cp->font) || - (p->uniqueitem_counter != cp->uniqueitem_counter ) + (p->uniqueitem_counter != cp->uniqueitem_counter ) || (p->sex != cp->sex) ) { //Save status unsigned int opt = 0; + char sex; if( p->allow_party ) opt |= OPT_ALLOW_PARTY; if( p->show_equip ) opt |= OPT_SHOW_EQUIP; + switch (p->sex) + { + case 0: + sex = 'F'; + break; + case 1: + sex = 'M'; + break; + case 99: + default: + sex = 'U'; + break; + } + if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `base_level`='%d', `job_level`='%d'," "`base_exp`='%u', `job_exp`='%u', `zeny`='%d'," "`max_hp`='%d',`hp`='%d',`max_sp`='%d',`sp`='%d',`status_point`='%d',`skill_point`='%d'," @@ -470,7 +485,8 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) "`option`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d',`homun_id`='%d',`elemental_id`='%d'," "`weapon`='%d',`shield`='%d',`head_top`='%d',`head_mid`='%d',`head_bottom`='%d'," "`last_map`='%s',`last_x`='%d',`last_y`='%d',`save_map`='%s',`save_x`='%d',`save_y`='%d', `rename`='%d'," - "`delete_date`='%lu',`robe`='%d',`slotchange`='%d', `char_opt`='%u', `font`='%u', `uniqueitem_counter` ='%u'" + "`delete_date`='%lu',`robe`='%d',`slotchange`='%d', `char_opt`='%u', `font`='%u', `uniqueitem_counter` ='%u'," + " sex = '%c'" " WHERE `account_id`='%d' AND `char_id` = '%d'", char_db, p->base_level, p->job_level, p->base_exp, p->job_exp, p->zeny, @@ -481,7 +497,7 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p) mapindex_id2name(p->last_point.map), p->last_point.x, p->last_point.y, mapindex_id2name(p->save_point.map), p->save_point.x, p->save_point.y, p->rename, (unsigned long)p->delete_date, // FIXME: platform-dependent size - p->robe,p->slotchange,opt,p->font,p->uniqueitem_counter, + p->robe,p->slotchange,opt,p->font,p->uniqueitem_counter, sex, p->account_id, p->char_id) ) { Sql_ShowDebug(inter->sql_handle); -- cgit v1.2.3-70-g09d2 From 14d0fb868e86c676cdf70dfacaf33d4330d5f011 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 21 Dec 2014 14:36:11 +0300 Subject: Add script function for change per character gender. New script function: changecharsex --- src/map/script.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/map/script.c b/src/map/script.c index c7b1ae849..031dfc21b 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -10639,26 +10639,50 @@ BUILDIN(changebase) { return true; } +static TBL_PC *prepareChangeSex(struct script_state* st) +{ + int i; + TBL_PC *sd = script->rid2sd(st); + + if (sd == NULL) + return NULL; + + pc->resetskill(sd, 4); + // to avoid any problem with equipment and invalid sex, equipment is unequiped. + for (i=0; iequip_index[i] >= 0) pc->unequipitem(sd, sd->equip_index[i], 3); + return sd; +} + /*========================================== * Unequip all item and request for a changesex to char-serv *------------------------------------------*/ BUILDIN(changesex) { - int i; - TBL_PC *sd = NULL; - sd = script->rid2sd(st); - - if( sd == NULL ) + TBL_PC *sd = prepareChangeSex(st); + if (sd == NULL) return false; - - pc->resetskill(sd,4); - // to avoid any problem with equipment and invalid sex, equipment is unequiped. - for( i=0; iequip_index[i] >= 0 ) pc->unequipitem(sd, sd->equip_index[i], 3); chrif->changesex(sd); return true; } +/*========================================== + * Unequip all items and change character sex [4144] + *------------------------------------------*/ +BUILDIN(changecharsex) +{ + TBL_PC *sd = prepareChangeSex(st); + if (sd == NULL) + return false; + if (sd->status.sex == 99) + sd->status.sex = 0; + sd->status.sex = sd->status.sex ? 0 : 1; + chrif->save(sd, 0); + if (sd->fd) + clif->authfail_fd(sd->fd, 15); + return true; +} + /*========================================== * Works like 'announce' but outputs in the common chat window *------------------------------------------*/ @@ -19302,6 +19326,7 @@ void script_parse_builtin(void) { BUILDIN_DEF(skillpointcount,""), BUILDIN_DEF(changebase,"i?"), BUILDIN_DEF(changesex,""), + BUILDIN_DEF(changecharsex,""), // [4144] BUILDIN_DEF(waitingroom,"si?????"), BUILDIN_DEF(delwaitingroom,"?"), BUILDIN_DEF2(waitingroomkickall,"kickwaitingroomall","?"), -- cgit v1.2.3-70-g09d2