summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-03-21 21:13:47 +0000
committerskotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-03-21 21:13:47 +0000
commit2497231d154686820451009c252fd9fc7ed4b808 (patch)
tree50fb4d9d31123fa273865013f24e9522b4a829e7 /src
parent6c6cfb325ea28e5bf8d137e057eb0716b0b8a4d0 (diff)
downloadhercules-2497231d154686820451009c252fd9fc7ed4b808.tar.gz
hercules-2497231d154686820451009c252fd9fc7ed4b808.tar.bz2
hercules-2497231d154686820451009c252fd9fc7ed4b808.tar.xz
hercules-2497231d154686820451009c252fd9fc7ed4b808.zip
- Corrected setitemscript so it actually changes the script as requested instead of causing dangling pointers.
- Cleaned up unitattack - Made packet_ver_flag's description use hexadecimal values for the packet versions, and changed the default to 0xFFFF. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10047 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/map/script.c130
1 files changed, 66 insertions, 64 deletions
diff --git a/src/map/script.c b/src/map/script.c
index e75456b63..62c88a8b9 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -12198,27 +12198,34 @@ BUILDIN_FUNC(setitemscript)
int item_id,n=0;
const char *script;
struct item_data *i_data;
- struct script_code *dstscript;
+ struct script_code **dstscript;
item_id = conv_num(st,script_getdata(st,2));
script = conv_str(st,script_getdata(st,3));
- if( st->end>st->start+4 )
+ if( script_hasdata(st,4) )
n=conv_num(st,script_getdata(st,4));
i_data = itemdb_exists(item_id);
- if (i_data && script!=NULL && script[0]=='{' && n<3) {
- if(n==2)
- dstscript = i_data->unequip_script;
- else if(n==1)
- dstscript = i_data->equip_script;
- else
- dstscript = i_data->script;
- if(dstscript)
- script_free_code(dstscript);
- dstscript = parse_script(script, "script_setitemscript", 0, 0);
- script_pushint(st,1);
- } else
+ if (!i_data || script==NULL || script[0]!='{') {
script_pushint(st,0);
+ return 0;
+ }
+ switch (n) {
+ case 2:
+ dstscript = &i_data->unequip_script;
+ break;
+ case 1:
+ dstscript = &i_data->equip_script;
+ break;
+ default:
+ dstscript = &i_data->script;
+ break;
+ }
+ if(*dstscript)
+ script_free_code(*dstscript);
+
+ *dstscript = parse_script(script, "script_setitemscript", 0, 0);
+ script_pushint(st,1);
return 0;
}
@@ -12838,14 +12845,10 @@ BUILDIN_FUNC(unitwarp)
y = (short)conv_num(st, script_getdata(st,5));
bl = map_id2bl(unit_id);
- if( map > 0 && bl != NULL )
- {
+ if( map >= 0 && bl != NULL )
script_pushint(st, unit_warp(bl,map,x,y,0));
- }
else
- {
script_pushint(st, 0);
- }
return 0;
}
@@ -12860,57 +12863,56 @@ BUILDIN_FUNC(unitwarp)
BUILDIN_FUNC(unitattack)
{
struct block_list* unit_bl;
+ struct block_list* target_bl = NULL;
+ struct script_data* data;
+ int actiontype = 0;
// get unit
unit_bl = map_id2bl(conv_num(st, script_getdata(st, 2)));
- if( unit_bl != NULL )
+ if( unit_bl == NULL ) {
+ script_pushint(st, 0);
+ return 0;
+ }
+
+ data = script_getdata(st, 3);
+ get_val(st, data);
+ if( data_isstring(data) )
{
- struct block_list* target_bl = NULL;
- struct script_data* data;
- int actiontype = 0;
-
- // get target
- data = script_getdata(st, 3);
- get_val(st, data);
- if( data_isstring(data) )
- {
- struct map_session_data* sd = map_nick2sd(conv_str(st, data));
- if( sd != NULL )
- target_bl = &sd->bl;
- }
- if( target_bl == NULL )
- target_bl = map_id2bl(conv_num(st, data));
-
- // get actiontype
- if( script_hasdata(st,4) )
- actiontype = conv_num(st, script_getdata(st, 4));
-
- // request the attack
- if( target_bl != NULL )
- {
- switch( unit_bl->type )
- {
- case BL_PC:
- clif_parse_ActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, gettick());
- script_pushint(st, 1);
- return 0;
- case BL_MOB:
- ((TBL_MOB *)unit_bl)->state.killer = 1;
- ((TBL_MOB *)unit_bl)->target_id = target_bl->id;
- break;
- case BL_PET:
- ((TBL_PET *)unit_bl)->target_id = target_bl->id;
- break;
- default:
- ShowError("script:unitattack: unsupported source unit type %d\n", unit_bl->type);
- script_pushint(st, 0);
- return 0;
- }
- script_pushint(st, unit_walktobl(unit_bl, target_bl, 65025, 2));
- }
+ struct map_session_data* sd = map_nick2sd(conv_str(st, data));
+ if( sd != NULL )
+ target_bl = &sd->bl;
+ } else
+ target_bl = map_id2bl(conv_num(st, data));
+ // request the attack
+ if( target_bl == NULL )
+ {
+ script_pushint(st, 0);
+ return 0;
}
- script_pushint(st, 0);
+
+ // get actiontype
+ if( script_hasdata(st,4) )
+ actiontype = conv_num(st, script_getdata(st, 4));
+ switch( unit_bl->type )
+ {
+ case BL_PC:
+ clif_parse_ActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, gettick());
+ script_pushint(st, 1);
+ return 0;
+ case BL_MOB:
+ ((TBL_MOB *)unit_bl)->state.killer = 1;
+ ((TBL_MOB *)unit_bl)->target_id = target_bl->id;
+ break;
+ case BL_PET:
+ ((TBL_PET *)unit_bl)->target_id = target_bl->id;
+ break;
+ default:
+ ShowError("script:unitattack: unsupported source unit type %d\n", unit_bl->type);
+ script_pushint(st, 0);
+ return 0;
+ }
+ script_pushint(st, unit_walktobl(unit_bl, target_bl, 65025, 2));
return 0;
}