View Full Version : [SOLVED] Need help creating a timer!

04-20-2016, 10:40 PM
Hey! I'm trying to create a timer for my boss. Right now I am using a code I found on the forum but I think using "os.time" is not the right way to go when creating a timer.
To me "os.time" sounds like it is using the clients time and not the server. Is there any other way or is this the way to go?

Saw some posts about "GetGameTime" but I can't figure out how it works...

Thanks in advance! --Butterz

function MovedToLocation1(event, delay, pCall, creature, player)
wait(8) -- Calls the wait function below
creature:RegisterEvent(NiklasSpell2, 100, 0)

function wait(seconds)
local _start = os.time()
local _end = _start+seconds
while (_end ~= os.time()) do

04-20-2016, 10:52 PM
Why don't you just set the RegisterEvent timer to 8 seconds? Doesn't make much sense to have another timer at 8 seconds and then call another timed event afterwards.

04-20-2016, 11:07 PM
The code after the wait is temporary right now. I dont want to create so many functions for everything that is why I want some kind of wait function.

Let's say I want him to do something and then speak. Wait some time and then continue with something, in the same function.


function MovedToLocation1(event, delay, pCall, creature, player)
creature:SendUnitYell("I am dead, no big suprise", 0)
creature:SendUnitYell("HAH fool'd ya!", 0)
creature:RegisterEvent(NiklasSpell2, 100, 1)

- - - Updated - - -

My example actually worked...

Thanks for fast awnser anyways... I'm new <3

04-20-2016, 11:22 PM
note that the wait function halts the whole server for the time you want to wait. You should never do that.

04-20-2016, 11:23 PM
Do you have anything to recommend instead ?

04-21-2016, 01:52 PM
Timed events and OnWPReached hook should do the job for you :)

04-21-2016, 02:10 PM
Can you be more specific? I don't know what either of those are... ^^

Include a quick example if you can :))

04-21-2016, 03:22 PM
I will have to do some testing, and most likely it will not be exactly what you need at this point, but it will be a nice example regardless :P

04-21-2016, 03:42 PM
I'm eagerly waiting! :smile:

04-21-2016, 04:54 PM
Here you go, this is an example how to trigger timed events in conjunction with movement to waypoints, and keeping everything within just a couple functions. Tested by Rochet on Trinity.


The ID is the first number specified in the MoveTo method. This is then passed along to OnReachWP and then onto OnTimedEvent.

04-21-2016, 05:18 PM
HURRAY! Thanks a bunch, this works wounders. I'm quite intressted to understand it more, so I can write my own later. Could you explain this line?

creature:RegisterEvent(function(_, _, _, creature) OnTimedEvent(creature, id); return; end, 5000, 1)

04-21-2016, 05:23 PM
Normally you register a timed event like this:

creature:RegisterEvent(OnTimedEvent, 5000, 1)

This results in an argument list like this:

function OnTimedEvent(event, delay, repeats, creature)

However, in the above example, we create a "dummy" function;

function(_, _, _, creature) OnTimedEvent(creature, id); return; end

that calls OnTimedEvent and passes a custom set of arguments to that function (creature and id). Since we do not need event, delay, repeats we simply toss them to the garbage collector (_) and pass creature along to our OnTimedEvent function, as well as the id used to figure out at which point we are in the chain of events. Our resulting OnTimedEvent then looks like this:

function OnTimedEvent(creature, id)

So to clarify, we do it to be able to pass custom arguments to a timed event.

04-21-2016, 05:42 PM
Sweet! This might be the final question... Where can I find these parameters? Is there any list of 'em?

(event, creature, type, id)

04-21-2016, 06:43 PM

This link contains all the registers ie. RegisterCreatureEvent. Each event has a different set of arguments listed on their respective page.

04-21-2016, 07:49 PM
Thanks so much guys! Couldn't made it without y'all. It's all solved now! :) Made two guards patrol.

Can be marked as solved!

--Cheers Butterfield