diff options
author | Inkfish <Inkfish@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2009-05-07 14:52:22 +0000 |
---|---|---|
committer | Inkfish <Inkfish@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2009-05-07 14:52:22 +0000 |
commit | 8a2839bcc9547e6e1239f87c6901a1fe46dc06a8 (patch) | |
tree | 6a75c3bbf2479d299a240deb0f3ca9ab3c1c1728 /src/map/script.c | |
parent | 7666e881212f15d7d8ed22ef6ee82f98b15c175c (diff) | |
download | hercules-8a2839bcc9547e6e1239f87c6901a1fe46dc06a8.tar.gz hercules-8a2839bcc9547e6e1239f87c6901a1fe46dc06a8.tar.bz2 hercules-8a2839bcc9547e6e1239f87c6901a1fe46dc06a8.tar.xz hercules-8a2839bcc9547e6e1239f87c6901a1fe46dc06a8.zip |
* Clean up for npc timer code
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13738 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/src/map/script.c b/src/map/script.c index 6fb3d662c..85cd4d095 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -7712,6 +7712,7 @@ BUILDIN_FUNC(initnpctimer) { struct npc_data *nd; int flag = 0; + if( script_hasdata(st,3) ) { //Two arguments: NPC name and attach flag. nd = npc_name2id(script_getstr(st, 2)); @@ -7736,11 +7737,11 @@ BUILDIN_FUNC(initnpctimer) } } else - nd=(struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)map_id2bl(st->oid); - if (!nd) + if( !nd ) return 0; - if (flag) //Attach + if( flag ) //Attach { TBL_PC* sd = script_rid2sd(st); if( sd == NULL ) @@ -7759,6 +7760,7 @@ BUILDIN_FUNC(startnpctimer) { struct npc_data *nd; int flag = 0; + if( script_hasdata(st,3) ) { //Two arguments: NPC name and attach flag. nd = npc_name2id(script_getstr(st, 2)); @@ -7785,9 +7787,9 @@ BUILDIN_FUNC(startnpctimer) else nd=(struct npc_data *)map_id2bl(st->oid); - if (!nd) + if( !nd ) return 0; - if (flag) //Attach + if( flag ) //Attach { TBL_PC* sd = script_rid2sd(st); if( sd == NULL ) @@ -7805,6 +7807,7 @@ BUILDIN_FUNC(stopnpctimer) { struct npc_data *nd; int flag = 0; + if( script_hasdata(st,3) ) { //Two arguments: NPC name and attach flag. nd = npc_name2id(script_getstr(st, 2)); @@ -7831,9 +7834,9 @@ BUILDIN_FUNC(stopnpctimer) else nd=(struct npc_data *)map_id2bl(st->oid); - if (!nd) + if( !nd ) return 0; - if (flag) //Detach + if( flag ) //Detach nd->u.scr.rid = 0; npc_timerevent_stop(nd); @@ -7846,35 +7849,41 @@ BUILDIN_FUNC(getnpctimer) { struct npc_data *nd; TBL_PC *sd; - int type=script_getnum(st,2); - int val=0; + int type = script_getnum(st,2); + int val = 0; + if( script_hasdata(st,3) ) nd = npc_name2id(script_getstr(st,3)); else nd = (struct npc_data *)map_id2bl(st->oid); - if (!nd || nd->bl.type != BL_NPC) + if( !nd || nd->bl.type != BL_NPC ) { script_pushint(st,0); ShowError("getnpctimer: Invalid NPC.\n"); return 1; } - switch(type){ - case 0: val=npc_gettimerevent_tick(nd); break; + switch( type ) + { + case 0: val = npc_gettimerevent_tick(nd); break; case 1: - if (nd->u.scr.rid) { + if( nd->u.scr.rid ) + { sd = map_id2sd(nd->u.scr.rid); - if (!sd) { + if( !sd ) + { ShowError("buildin_getnpctimer: Attached player not found!\n"); break; } val = (sd->npc_timer_id != -1); - } else - val= (nd->u.scr.timerid !=-1); + } + else + val = (nd->u.scr.timerid !=-1); break; - case 2: val= nd->u.scr.timeramount; break; + case 2: val = nd->u.scr.timeramount; break; } + script_pushint(st,val); return 0; } @@ -7885,13 +7894,14 @@ BUILDIN_FUNC(setnpctimer) { int tick; struct npc_data *nd; - tick=script_getnum(st,2); + + tick = script_getnum(st,2); if( script_hasdata(st,3) ) - nd=npc_name2id(script_getstr(st,3)); + nd = npc_name2id(script_getstr(st,3)); else - nd=(struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)map_id2bl(st->oid); - if (!nd || nd->bl.type != BL_NPC) + if( !nd || nd->bl.type != BL_NPC ) { script_pushint(st,1); ShowError("setnpctimer: Invalid NPC.\n"); @@ -7909,11 +7919,9 @@ BUILDIN_FUNC(setnpctimer) BUILDIN_FUNC(attachnpctimer) { TBL_PC *sd; - struct npc_data *nd; + struct npc_data *nd = (struct npc_data *)map_id2bl(st->oid); - nd=(struct npc_data *)map_id2bl(st->oid); - - if (!nd || nd->bl.type != BL_NPC) + if( !nd || nd->bl.type != BL_NPC ) { script_pushint(st,1); ShowError("setnpctimer: Invalid NPC.\n"); @@ -7921,11 +7929,11 @@ BUILDIN_FUNC(attachnpctimer) } if( script_hasdata(st,2) ) - sd=map_nick2sd(script_getstr(st,2)); + sd = map_nick2sd(script_getstr(st,2)); else sd = script_rid2sd(st); - if (!sd) + if( !sd ) { script_pushint(st,1); ShowWarning("attachnpctimer: Invalid player.\n"); @@ -7943,12 +7951,13 @@ BUILDIN_FUNC(attachnpctimer) BUILDIN_FUNC(detachnpctimer) { struct npc_data *nd; + if( script_hasdata(st,2) ) - nd=npc_name2id(script_getstr(st,2)); + nd = npc_name2id(script_getstr(st,2)); else - nd=(struct npc_data *)map_id2bl(st->oid); + nd = (struct npc_data *)map_id2bl(st->oid); - if (!nd || nd->bl.type != BL_NPC) + if( !nd || nd->bl.type != BL_NPC ) { script_pushint(st,1); ShowError("detachnpctimer: Invalid NPC.\n"); |