• 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 Use addEvent properly with loops

Making this function like this you made a live a bit easier, again :)
Any way I'm curious if that will work with ObjectOrientated function, like this from npc system :p
Anyway you are making short, very usefull and advenced stuff. You are my HERO :D
 
Bump for the smart people

Damn...I wanted this to remain forgotten until I released my "jail script with countdown resume in case the player logs out with no loops whatsoever". Oh well...for scripters out there: this addEvent trick is really, REALLY useful.
Just a preview of my code:
Lua:
function doCreatureSetCountdown(uid, key, time, delay)
	doCreatureSetStorage(uid, key, time)
	if(getCreatureStorage(uid, key) > 0) then
		addEvent(function(uid, key, time)
			if(isPlayer(uid) and getCreatureStorage(uid, key) > 0) then
				doCreatureSetCountdown(uid, key, time, delay)
			end
		end, delay, uid, key, time - 1, delay)
	end

	return true
end
 
actually I prefer it this way(for multiple loops), but i*delay looks great too
Code:
delay = 500
for a = 1, 10 do
for b = 1, 20 do
addEvent(print, delay, a.." "..b)
delay = delay + 500
end
end
 
Back
Top