summaryrefslogtreecommitdiff
path: root/src/map/npc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/npc.c')
-rw-r--r--src/map/npc.c34
1 files changed, 18 insertions, 16 deletions
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 )
{