From 6aa0357455a54308aa7d52b3b262002b7f03d478 Mon Sep 17 00:00:00 2001 From: Inkfish Date: Sat, 9 May 2009 16:12:28 +0000 Subject: * Fixed NPC timer errors - ted->rid is not initialized for global timer - timer_id is not set to INVALID_TIMER when timer is deleted - run script after next event is arranged git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13746 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/npc.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/map/npc.c b/src/map/npc.c index b9dd2fd51..f5a1bfc09 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -449,17 +449,8 @@ int npc_timerevent(int tid, unsigned int tick, int id, intptr data) nd->u.scr.timertick = tick; //current time tick nd->u.scr.timer = ted->time; //total time from beginning to now - // Run the script + // Locate the event te = nd->u.scr.timer_event + ted->next; - run_script(nd->u.scr.script,te->pos,nd->u.scr.rid,nd->bl.id); - - - nd->u.scr.rid = old_rid; // Attached-rid should be restored anyway. - if( sd ) - { // Restore previous data, only if this timer is a player-attached one. - nd->u.scr.timer = old_timer; - nd->u.scr.timertick = old_tick; - } // Arrange for the next event ted->next++; @@ -484,6 +475,16 @@ int npc_timerevent(int tid, unsigned int tick, int id, intptr data) ers_free(timer_event_ers, ted); } + // Run the script + run_script(nd->u.scr.script,te->pos,nd->u.scr.rid,nd->bl.id); + + nd->u.scr.rid = old_rid; // Attached-rid should be restored anyway. + if( sd ) + { // Restore previous data, only if this timer is a player-attached one. + nd->u.scr.timer = old_timer; + nd->u.scr.timertick = old_tick; + } + return 0; } /*========================================== @@ -534,6 +535,7 @@ int npc_timerevent_start(struct npc_data* nd, int rid) } else { + ted->rid = 0; nd->u.scr.timertick = tick; // Set when timer is started nd->u.scr.timerid = add_timer(tick+next,npc_timerevent,nd->bl.id,(intptr)ted); } @@ -547,7 +549,7 @@ int npc_timerevent_stop(struct npc_data* nd) { struct map_session_data *sd = NULL; const struct TimerData *td = NULL; - int tid; + int *tid; nullpo_retr(0, nd); @@ -557,16 +559,16 @@ int npc_timerevent_stop(struct npc_data* nd) return 1; } - tid = sd?sd->npc_timer_id:nd->u.scr.timerid; - if( tid == -1 ) // Nothing to stop + tid = sd?&sd->npc_timer_id:&nd->u.scr.timerid; + if( *tid == -1 ) // Nothing to stop return 0; // Delete timer - td = get_timer(tid); + td = get_timer(*tid); if( td && td->data ) ers_free(timer_event_ers, (void*)td->data); - delete_timer(tid,npc_timerevent); - tid = -1; + delete_timer(*tid,npc_timerevent); + *tid = -1; if( !sd ) { -- cgit v1.2.3-70-g09d2