diff options
author | gumi <git@gumi.ca> | 2018-10-01 20:50:27 -0400 |
---|---|---|
committer | gumi <git@gumi.ca> | 2018-10-01 22:39:50 -0400 |
commit | 191a266c155085d467e7c73c5553159b5556fdfc (patch) | |
tree | 1d570f667dfd2e3c461794c661daea06529eaa91 /src | |
parent | 3ced983fc5d26f69896ce62230c48d6e2faa04fd (diff) | |
download | hercules-191a266c155085d467e7c73c5553159b5556fdfc.tar.gz hercules-191a266c155085d467e7c73c5553159b5556fdfc.tar.bz2 hercules-191a266c155085d467e7c73c5553159b5556fdfc.tar.xz hercules-191a266c155085d467e7c73c5553159b5556fdfc.zip |
use the regular pc->setregistry to set vars of another char
this will prevent further errors, and will allow setting special variables such as `#CASHPOINTS`
Diffstat (limited to 'src')
-rw-r--r-- | src/map/script.c | 115 |
1 files changed, 12 insertions, 103 deletions
diff --git a/src/map/script.c b/src/map/script.c index 094e32127..422085c42 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -3316,119 +3316,28 @@ static void set_reg_npcscope_str(struct script_state *st, struct reg_db *n, int6 static void set_reg_pc_ref_str(struct script_state *st, struct reg_db *n, int64 num, const char *name, const char *str) { - struct script_reg_str *p = NULL; - unsigned int index = script_getvaridx(num); - - nullpo_retv(n); - - if ((p = i64db_get(n->vars, num)) != NULL) { - if (str[0]) { - if (p->value) { - aFree(p->value); - } else if (index) { - script->array_update(n, num, false); - } - p->value = aStrdup(str); - } else { - p->value = NULL; - if (index) { - script->array_update(n, num, true); - } - } - - if (!pc->reg_load) { - p->flag.update = 1; - } - } else if (str[0]) { - struct DBData prev; - if (index) { - script->array_update(n, num, false); - } - - p = ers_alloc(pc->str_reg_ers, struct script_reg_str); - p->value = aStrdup(str); - - if (!pc->reg_load) { - p->flag.update = 1; - } - p->flag.type = 1; + struct DBIterator *iter = db_iterator(map->pc_db); - if(n->vars->put(n->vars, DB->i642key(num), DB->ptr2data(p), &prev)) { - p = DB->data2ptr(&prev); - if (p->value) { - aFree(p->value); - } - ers_free(pc->str_reg_ers, p); - } - } - - if (!pc->reg_load && p != NULL) { - struct DBIterator *iter = db_iterator(map->pc_db); - - for (struct map_session_data *sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) { - if (sd != NULL && n == &sd->regs) { - sd->vars_dirty = true; // tell char server to update our vars! - break; - } + for (struct map_session_data *sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) { + if (sd != NULL && n == &sd->regs) { + pc->setregistry_str(sd, num, str); + break; } - dbi_destroy(iter); } + dbi_destroy(iter); } static void set_reg_pc_ref_num(struct script_state *st, struct reg_db *n, int64 num, const char *name, int val) { - struct script_reg_num *p = NULL; - unsigned int index = script_getvaridx(num); - - nullpo_retv(n); - - if ((p = i64db_get(n->vars, num)) != NULL) { - if (val) { - if (!p->value && index) { - script->array_update(n, num, false); - } - p->value = val; - } else { - p->value = 0; - if (index) { - script->array_update(n, num, true); - } - } - - if (!pc->reg_load) { - p->flag.update = 1; - } - } else if (val) { - struct DBData prev; - if (index) { - script->array_update(n, num, false); - } - - p = ers_alloc(pc->num_reg_ers, struct script_reg_num); - p->value = val; - - if (!pc->reg_load) { - p->flag.update = 1; - } - p->flag.type = 0; - - if(n->vars->put(n->vars, DB->i642key(num), DB->ptr2data(p), &prev)) { - p = DB->data2ptr(&prev); - ers_free(pc->num_reg_ers, p); - } - } + struct DBIterator *iter = db_iterator(map->pc_db); - if (!pc->reg_load && p != NULL) { - struct DBIterator *iter = db_iterator(map->pc_db); - - for (struct map_session_data *sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) { - if (sd != NULL && n == &sd->regs) { - sd->vars_dirty = true; // tell char server to update our vars! - break; - } + for (struct map_session_data *sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) { + if (sd != NULL && n == &sd->regs) { + pc->setregistry(sd, num, val); + break; } - dbi_destroy(iter); } + dbi_destroy(iter); } static void set_reg_npcscope_num(struct script_state *st, struct reg_db *n, int64 num, const char *name, int val) |