• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Need help creating a timer!

Status
Not open for further replies.
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

Code:
function MovedToLocation1(event, delay, pCall, creature, player)
	creature:RemoveEvents()
	creature:RemoveFlag(59,2)
	wait(8) -- Calls the wait function below
	creature:RegisterEvent(NiklasSpell2, 100, 0)
end

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

Tommy

Founder
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.
 
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.

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

- - - Updated - - -

My example actually worked...

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

Rochet2

Moderator / Eluna Dev
note that the wait function halts the whole server for the time you want to wait. You should never do that.
 

Foereaper

Founder
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
 

Foereaper

Founder
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.

http://pastebin.com/1qy9jxV6

The ID is the first number specified in the MoveTo method. This is then passed along to OnReachWP and then onto OnTimedEvent.
 
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?

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

Foereaper

Founder
Normally you register a timed event like this:

Code:
creature:RegisterEvent(OnTimedEvent, 5000, 1)

This results in an argument list like this:

Code:
function OnTimedEvent(event, delay, repeats, creature)

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

Code:
[COLOR="#FF0000"]function(_, _, _, creature)[/COLOR] OnTimedEvent(creature, id); [COLOR="#FF0000"]return; end[/COLOR]

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:

Code:
function OnTimedEvent(creature, id)

So to clarify, we do it to be able to pass custom arguments to a timed event.
 
Sweet! This might be the final question... Where can I find these parameters? Is there any list of 'em?

Code:
(event, creature, type, id)
 
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
 
Status
Not open for further replies.
Top