* Fixed dynamic shop arrays @bought_nameid, @bought_quantity, @sold_nameid and @sold_quantity not getting reset to zero before use, thus providing attached script with wrong/old data, if it did not clear them by itself in previous call (bugreport:1574, since r5841).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14611 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
ai4rei 2010-12-21 21:30:46 +00:00
parent 2a043e4999
commit 7c90fd1bf1
4 changed files with 47 additions and 0 deletions

View File

@ -1,6 +1,7 @@
Date Added
2010/12/21
* Fixed dynamic shop arrays @bought_nameid, @bought_quantity, @sold_nameid and @sold_quantity not getting reset to zero before use, thus providing attached script with wrong/old data, if it did not clear them by itself in previous call (bugreport:1574, since r5841). [Ai4rei]
* Removed 'strsignal' forward-declaration from 'sig' plugin to prevent random gcc distributions from failing to compile due to mismatched declaration already present in <string.h> (bugreport:4644, topic:262284, follow up to r14591). [Ai4rei]
- Removed WIN32 conditions in non-WIN32 code in 'sig' plugin (follow up to r4380).
2010/12/19

View File

@ -1144,6 +1144,11 @@ static int npc_buylist_sub(struct map_session_data* sd, int n, unsigned short* i
int i;
int regkey = add_str("@bought_nameid");
int regkey2 = add_str("@bought_quantity");
// discard old contents
script_cleararray_pc(sd, "@bought_nameid", (void*)0);
script_cleararray_pc(sd, "@bought_quantity", (void*)0);
snprintf(npc_ev, ARRAYLENGTH(npc_ev), "%s::OnBuyItem", nd->exname);
for(i=0;i<n;i++){
pc_setreg(sd,regkey+(i<<24),(int)item_list[i*2+1]);
@ -1371,6 +1376,13 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list)
return 1;
nd = nd->master_nd; //For OnSell triggers.
if( nd )
{
// discard old contents
script_cleararray_pc(sd, "@sold_nameid", (void*)0);
script_cleararray_pc(sd, "@sold_quantity", (void*)0);
}
for(i=0,z=0;i<n;i++) {
int nameid, idx;
short qty;

View File

@ -3547,6 +3547,38 @@ void script_add_autobonus(const char *autobonus)
}
}
/// resets a temporary character array variable to given value
void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value)
{
int key;
uint8 idx;
if( not_array_variable(varname[0]) || !not_server_variable(varname[0]) )
{
ShowError("script_cleararray_pc: Variable '%s' has invalid scope (char_id=%d).\n", varname, sd->status.char_id);
return;
}
key = add_str(varname);
if( is_string_variable(varname) )
{
for( idx = 0; idx < SCRIPT_MAX_ARRAYSIZE; idx++ )
{
pc_setregstr(sd, reference_uid(key, idx), (const char*)value);
}
}
else
{
for( idx = 0; idx < SCRIPT_MAX_ARRAYSIZE; idx++ )
{
pc_setreg(sd, reference_uid(key, idx), (int)value);
}
}
}
/*==========================================
* <EFBFBD>I¹
*------------------------------------------*/

View File

@ -167,6 +167,8 @@ struct DBMap* script_get_label_db(void);
struct DBMap* script_get_userfunc_db(void);
void script_run_autobonus(const char *autobonus,int id, int pos);
void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value);
int script_config_read(char *cfgName);
int do_init_script(void);
int do_final_script(void);