• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua AddEvent function, help

Raiden

Developer
Joined
Sep 16, 2008
Messages
486
Reaction score
32
Location
Venezuela
Hello, i have a script, for example, when i pull a lever a wall dissapear, i want to make it appear again after X time, but i don't know how, somebody tell me to use addEvent, but i have no idea how to use this function, help please
 
My LUA is a bit outdated but I guess I'll try..

AddEvent basically lets you add an event that happens after a set ammount of time, like this:

Lua:
AddEvent(Function, time, nil)

So you could just add the function as what creates the wall you want and be done with it, but
what makes it awesome is that you can create your own function and call it back.

So imagine you have a basic script

Lua:
function onUse(blabla)

-- This is the custom made function to do whatever happens after AddEVent timer runs out
local function MyFunc()
	doCreateItem etc
end
	blablabla
		blablabla
			AddEvent(MyFunc, 10000, nil)
end

This might be incredibly fucked because it's a function inside a function, but this should give you an idea of how it works.

Here's the line to just create the wall after a set ammount of time I guess..
Lua:
AddEvent(doCreateItem(1337, {x=37, y=37, z=37}), 10000, nil)
Replace Ids and positions as needed.
 
AddEvent can be used like a delay, much like he explained above, however dodging the syntax errors.

Lua:
AddEvent(doCreateItem(1337, {x=37, y=37, z=37}), 10000, nil) -- incorrect

AddEvent(doCreateItem, 10000, 1337, {x=37, y=37, z=37}) --correct

You pass the parameters of the function after the second parameter (time in ms).
 
Back
Top