• 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 Timer/Coldown

Core_

Well-Known Member
Joined
Jul 9, 2010
Messages
1,557
Solutions
1
Reaction score
50
I've always had this trouble and I hope someone could help me here.

I got this simple teleport script:

Lua:
local temple = {x = 1006, y = 999, z = 7}
shops = {x = 1025, y = 985, z = 7}
function onStepIn(cid, item, pos, fromPos)
	if item.itemid == 3188 then
		doTeleportThing(cid, shops) 
		doSendMagicEffect(shops, CONST_ME_MAGIC_GREEN)
	elseif item.itemid == 3196 then 
		doTeleportThing(cid, temple) 
		doSendMagicEffect(temple, CONST_ME_MAGIC_GREEN)
	end
end

Now, I want it to have to wait x time, before teleporting, example: You step in the tile then after 3 seconds you teleport, and maybe send some effect after each second that passes.

So I'll get something like :

Lua:
local temple = {x = 1006, y = 999, z = 7}
shops = {x = 1025, y = 985, z = 7}
function onStepIn(cid, item, pos, fromPos)
	if item.itemid == 3188 then
		passSecond()
		doSendMagicEffect(cid, CONST_ME_POFF)
		passSecond()
		doSendMagicEffect(cid, CONST_ME_POFF)
		passSecond()
		doSendMagicEffect(cid, CONST_ME_POFF)
		doTeleportThing(cid, shops) 
		doSendMagicEffect(shops, CONST_ME_MAGIC_GREEN)
	elseif item.itemid == 3196 then 
		doTeleportThing(cid, temple) 
		doSendMagicEffect(temple, CONST_ME_MAGIC_GREEN)
	end
end

I hope you get what I mean :), thanks in advance.
 
Code:
local temple = {x = 1006, y = 999, z = 7}
shops = {x = 1025, y = 985, z = 7}

_doSendMagicEffect = function (cid, effect)
	return isCreature(cid) and doSendMagicEffect(getThingPos(cid), effect)
end


function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
	if item.itemid == 3188 then
		createThread(function()
			wait(1000)
			_doSendMagicEffect(cid, CONST_ME_POFF)
			wait(1000)
			_doSendMagicEffect(cid, CONST_ME_POFF)
			wait(1000)
			_doSendMagicEffect(cid, CONST_ME_POFF)
			return isCreature(cid) and doTeleportThing(cid, shops), doSendMagicEffect(shops, CONST_ME_MAGIC_GREEN)
		end)
	elseif item.itemid == 3196 then 
		doTeleportThing(cid, temple) 
		doSendMagicEffect(temple, CONST_ME_MAGIC_GREEN)
	end
end

if you get an event error, you'll have to fix your couroutine lib(data\lib\002-wait.lua) like I had to do with my 0.3.6
change
Code:
function runThread(co)
    if(coroutine.status(co) ~= 'dead') then
        local _, delay = coroutine.resume(co)
        addEvent(continueThread, delay, co)
    end
end
to
Code:
function runThread(co)
    if(coroutine.status(co) ~= 'dead') then
        local _, delay = coroutine.resume(co)
        addEvent(runThread, delay, co)
    end
end
 
Last edited:
Back
Top