• 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] [Eluna] call a function every second

Status
Not open for further replies.

Cryhme187

New member
Hey,

i'm currently working on a script based on the servers time. i want to register a handler on server startup that creates an infinite function call loop with time offset t. within this function i want to check if currTime >= defTime then...

Do you know some example script or shared script i can look into to learn off? I've already checked the eluna api docs but i did not find something useful.

thanks
 

Rochet2

Moderator / Eluna Dev
http://eluna.emudevs.com/Global/CreateLuaEvent.html
http://eluna.emudevs.com/WorldObject/RegisterEvent.html

Both are used in similar way, but the second one also passes the world object that the event was registered for to the function that is executed when the timed event is executed.

Example:

Code:
local function MyTimedFunction(eventid, delay, repeats)
    print("A second has passed")
end

-- make the timed event when the script is run on startup or reload
CreateLuaEvent(MyTimedFunction, t, 0) -- t is your time in ms

If you really want to use the time diff method that you seem to write about in your main post, then you can try some of these:
http://eluna.emudevs.com/Global/RegisterCreatureEvent.html
CREATURE_EVENT_ON_AIUPDATE = 7, // (event, creature, diff)

http://eluna.emudevs.com/Global/RegisterMapEvent.html
INSTANCE_EVENT_ON_UPDATE = 3, // (event, map, diff)

http://eluna.emudevs.com/Global/RegisterServerEvent.html
WORLD_EVENT_ON_UPDATE = 13, // (event, diff)

You most likely want to use the last or the first one of these
 

Cryhme187

New member
Thanks for your fast reply, thats exactly what i was looking for.
Can you provide more information related to the 3 events you've mentioned? I have re-read their doc's pages but i can not find any information on when they gett called. That would be an useful addition to the doc's too.

thanks
 

Tommy

Founder
Thanks for your fast reply, thats exactly what i was looking for.
Can you provide more information related to the 3 events you've mentioned? I have re-read their doc's pages but i can not find any information on when they gett called. That would be an useful addition to the doc's too.

thanks

They are update events so they are called every x tick after registering the said event(s). You could also test by printing test text to console/ingame after registering an event.
 

Rochet2

Moderator / Eluna Dev
In addition to what tommy said you should know that
CREATURE_EVENT_ON_AIUPDATE = 7, // (event, creature, diff)
is being called when a creature is in view of a player (exists ingame and is loaded)
If a creature is in some other plain of visibility even if a player is next to it, it may not be updated or loaded.

INSTANCE_EVENT_ON_UPDATE = 3, // (event, map, diff)
is being called when a map is loaded and active

WORLD_EVENT_ON_UPDATE = 13, // (event, diff)
is being called all the time no matter what circumstances
 

Cryhme187

New member
thanks, again exactly what i needed. I asked because i dont want to generate too much load by the timediff check. Currently i'm thinking about running it with an 5 minutes interval as it has only to precise to the day.

thanks
 
Status
Not open for further replies.
Top