Browse Source

Added Shinomori's changes to npc event timers

git-svn-id: https://svn.code.sf.net/p/rathena/svn/branches/stable@953 54d463be-8e91-2dee-dedb-b68131a5f0ec
celest 20 years ago
parent
commit
c50add18b1
4 changed files with 13 additions and 10 deletions
  1. 2 0
      Changelog.txt
  2. 8 6
      src/map/npc.c
  3. 1 1
      src/map/npc.h
  4. 2 3
      src/map/script.c

+ 2 - 0
Changelog.txt

@@ -1,5 +1,7 @@
 Date	Added
 01/11
+        * Added Shinomori's changes to npc event timers (I never realised it, thanks
+          ^^; ) [celest]
         * Updated clif.c to be able to identify client versions based on the packet DB
           [celest]
         * Correct packet_db_ver to the maximum version allowed if it was set too high 

+ 8 - 6
src/map/npc.c

@@ -596,7 +596,7 @@ int npc_timerevent(int tid,unsigned int tick,int id,int data)
  * ƒ^ƒCƒ}�[ƒCƒxƒ“ƒgŠJŽn
  *------------------------------------------
  */
-int npc_timerevent_start(struct npc_data *nd)
+int npc_timerevent_start(struct npc_data *nd, int rid)
 {
 	int j,n, next;
 
@@ -610,12 +610,13 @@ int npc_timerevent_start(struct npc_data *nd)
 		if( nd->u.scr.timer_event[j].timer > nd->u.scr.timer )
 			break;
 	}
+	if(j>=n) // check if there is a timer to use !!BEFORE!! you write stuff to the structures [Shinomori]
+		return 0;
+
 	nd->u.scr.nexttimer=j;
 	nd->u.scr.timertick=gettick();
-	nd->u.scr.rid=0;	// reset attached player [celest]
-
-	if(j>=n)
-		return 0;
+	if (rid >= 0) nd->u.scr.rid=rid;	// changed to: attaching to given rid by default [Shinomori]
+	// if rid is less than 0 leave it unchanged [celest]
 	
 	next = nd->u.scr.timer_event[j].timer - nd->u.scr.timer;
 	nd->u.scr.timerid = add_timer(gettick()+next,npc_timerevent,nd->bl.id,next);
@@ -635,6 +636,7 @@ int npc_timerevent_stop(struct npc_data *nd)
 		if(nd->u.scr.timerid!=-1)
 			delete_timer(nd->u.scr.timerid,npc_timerevent);
 		nd->u.scr.timerid = -1;
+		nd->u.scr.rid = 0;
 	}
 	return 0;
 }
@@ -669,7 +671,7 @@ int npc_settimerevent_tick(struct npc_data *nd,int newtimer)
 	npc_timerevent_stop(nd);
 	nd->u.scr.timer=newtimer;
 	if(flag>=0)
-		npc_timerevent_start(nd);
+		npc_timerevent_start(nd, -1);
 	return 0;
 }
 

+ 1 - 1
src/map/npc.h

@@ -42,7 +42,7 @@ int npc_do_ontimer(int,struct map_session_data *,int);
 int npc_event_doall(const char *name);
 int npc_event_do(const char *name);
 
-int npc_timerevent_start(struct npc_data *nd);
+int npc_timerevent_start(struct npc_data *nd, int rid);
 int npc_timerevent_stop(struct npc_data *nd);
 int npc_gettimerevent_tick(struct npc_data *nd);
 int npc_settimerevent_tick(struct npc_data *nd,int newtimer);

+ 2 - 3
src/map/script.c

@@ -3892,8 +3892,7 @@ int buildin_initnpctimer(struct script_state *st)
 		nd=(struct npc_data *)map_id2bl(st->oid);
 
 	npc_settimerevent_tick(nd,0);
-	npc_timerevent_start(nd);
-	nd->u.scr.rid=st->rid;
+	npc_timerevent_start(nd, st->rid);
 	return 0;
 }
 /*==========================================
@@ -3908,7 +3907,7 @@ int buildin_startnpctimer(struct script_state *st)
 	else
 		nd=(struct npc_data *)map_id2bl(st->oid);
 
-	npc_timerevent_start(nd);
+	npc_timerevent_start(nd, st->rid);
 	return 0;
 }
 /*==========================================