This is like addEvent, but easier It exit when receiving errors, so you don't need "if isPlayer(cid) == TRUE then return FALSE end" because it exit itself when errors
TFS 0.3+ put in data/lib/functions.lua
TFS 0.2 or other put in data/global.lua
How to use? You need to do:
Example of talkaction script
If player logs out or dies, script will terminate... If you want something to happen if he logs out instead of just terminate you simply add "if isPlayer(cid) == FALSE then code_to_do_something end" (unfortunately you would need this each time a creature (or similar) function is called).
Update: Added support for parameters.
TFS 0.3+ put in data/lib/functions.lua
TFS 0.2 or other put in data/global.lua
Code:
sleep = coroutine.yield
function doSleep(co, ...)
if coroutine.status(co) ~= 'dead' then
local _, delay = coroutine.resume(co, ...)
addEvent(doSleep, delay, co)
end
end
function enableSleep(f, ...)
if type(f) == 'function' then
local co = coroutine.create(f)
doSleep(co, ...)
end
end
How to use? You need to do:
Code:
enableSleep(function()
-- CODE HERE and sleep will work :) Sleep dont work outside this!!
end)
Example of talkaction script
Code:
function onSay(cid, words, param)
param = tonumber(param)
if param and param > 0 and param < 60 then
enableSleep(function()
doCreatureSay(cid, "Time for suicide!", TALKTYPE_ORANGE_1)
for i = 1, param do
doCreatureSay(cid, "Suicide in " .. param - i .. " seconds!", TALKTYPE_ORANGE_1)
sleep(1000) -- delay a second
end
doCreatureSay(cid, "GOOD BYE :(", TALKTYPE_ORANGE_1)
doCreatureAddHealth(cid, -getCreatureHealth(cid))
end)
else
doPlayerSendCancel("Please enter a number between 1 and 59!")
end
end
If player logs out or dies, script will terminate... If you want something to happen if he logs out instead of just terminate you simply add "if isPlayer(cid) == FALSE then code_to_do_something end" (unfortunately you would need this each time a creature (or similar) function is called).
Update: Added support for parameters.
Last edited: