summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2017-03-12 04:15:44 +0100
committerGitHub <noreply@github.com>2017-03-12 04:15:44 +0100
commit7950c54a9a912b2c05d53afeaed7ddcda9caf196 (patch)
tree44591edea2069de286a6b0089f0dc55fbaaf450f
parent5321ac0bc44e4429bb443f7e2a2c9fea0e047cd4 (diff)
parentcc6db9e43dea9b0093d7f7617e6016b2635744dc (diff)
downloadhercules-7950c54a9a912b2c05d53afeaed7ddcda9caf196.tar.gz
hercules-7950c54a9a912b2c05d53afeaed7ddcda9caf196.tar.bz2
hercules-7950c54a9a912b2c05d53afeaed7ddcda9caf196.tar.xz
hercules-7950c54a9a912b2c05d53afeaed7ddcda9caf196.zip
Merge pull request #1610 from mekolat/timer2
allow the PC timer buildins to run on another player
-rw-r--r--doc/script_commands.txt9
-rw-r--r--src/map/script.c54
2 files changed, 42 insertions, 21 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 2f6f9b7ff..b202f1b6b 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -6478,15 +6478,16 @@ Size is 0 = normal 1 = small 2 = big.
//=====================================
---------------------------------------
-*addtimer(<ticks>, "NPC::OnLabel")
-*deltimer("NPC::OnLabel")
-*addtimercount("NPC::OnLabel", <ticks>)
+*addtimer(<ticks>, "NPC::OnLabel"{, <account id>})
+*deltimer("NPC::OnLabel"{, <account id>})
+*addtimercount("NPC::OnLabel", <ticks>{, <account id>})
These commands will create, destroy, and delay a countdown timer -
addtimer() to create, deltimer() to destroy and addtimercount() to delay
it by the specified number of ticks. For all three cases, the event label
given is the identifier of that timer. The timer runs on the character
-object that is attached to the script, and can have multiple instances.
+object that is attached to the script, and can have multiple instances.
+If <acccount id> is passed, this player will be used instead.
When the label is run, it is run as if the player that the timer runs on
has clicked the NPC.
diff --git a/src/map/script.c b/src/map/script.c
index 6e7598f9b..48c377d24 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -10791,19 +10791,29 @@ BUILDIN(donpcevent)
*------------------------------------------*/
BUILDIN(addtimer)
{
- int tick = script_getnum(st,2);
+ int tick = script_getnum(st, 2);
const char* event = script_getstr(st, 3);
struct map_session_data *sd;
script->check_event(st, event);
- sd = script->rid2sd(st);
- if( sd == NULL )
- return true;
- if (!pc->addeventtimer(sd,tick,event)) {
- ShowWarning("buildin_addtimer: Event timer is full, can't add new event timer. (cid:%d timer:%s)\n",sd->status.char_id,event);
+ if (script_hasdata(st, 4))
+ sd = map->id2sd(script_getnum(st, 4));
+ else
+ sd = script->rid2sd(st);
+
+ if (sd == NULL) {
+ script_pushint(st, 0);
+ return false;
+ }
+
+ if (!pc->addeventtimer(sd, tick, event)) {
+ ShowWarning("script:addtimer: Event timer is full, can't add new event timer. (cid:%d timer:%s)\n", sd->status.char_id, event);
+ script_pushint(st, 0);
return false;
}
+
+ script_pushint(st, 1);
return true;
}
/*==========================================
@@ -10814,12 +10824,17 @@ BUILDIN(deltimer)
struct map_session_data *sd;
event=script_getstr(st, 2);
- sd = script->rid2sd(st);
- if( sd == NULL )
+
+ if (script_hasdata(st, 3))
+ sd = map->id2sd(script_getnum(st, 3));
+ else
+ sd = script->rid2sd(st);
+
+ if (sd == NULL)
return true;
script->check_event(st, event);
- pc->deleventtimer(sd,event);
+ pc->deleventtimer(sd, event);
return true;
}
/*==========================================
@@ -10830,14 +10845,19 @@ BUILDIN(addtimercount)
int tick;
struct map_session_data *sd;
- event=script_getstr(st, 2);
- tick=script_getnum(st,3);
- sd = script->rid2sd(st);
- if( sd == NULL )
+ event = script_getstr(st, 2);
+ tick = script_getnum(st, 3);
+
+ if (script_hasdata(st, 4))
+ sd = map->id2sd(script_getnum(st, 4));
+ else
+ sd = script->rid2sd(st);
+
+ if (sd == NULL)
return true;
script->check_event(st, event);
- pc->addeventtimercount(sd,event,tick);
+ pc->addeventtimercount(sd, event, tick);
return true;
}
@@ -21092,9 +21112,9 @@ void script_parse_builtin(void) {
BUILDIN_DEF(clone,"siisi????"),
BUILDIN_DEF(doevent,"s"),
BUILDIN_DEF(donpcevent,"s"),
- BUILDIN_DEF(addtimer,"is"),
- BUILDIN_DEF(deltimer,"s"),
- BUILDIN_DEF(addtimercount,"si"),
+ BUILDIN_DEF(addtimer,"is?"),
+ BUILDIN_DEF(deltimer,"s?"),
+ BUILDIN_DEF(addtimercount,"si?"),
BUILDIN_DEF(initnpctimer,"??"),
BUILDIN_DEF(stopnpctimer,"??"),
BUILDIN_DEF(startnpctimer,"??"),