• 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!

Colandus

Advanced OT User
Senator
Joined
Jun 6, 2007
Messages
2,434
Solutions
19
Reaction score
219
Location
Sweden
Lua:
-----------------
-- By Colandus --

_CONT = {}
function continue(delay, n, ...)
    local func = debug.getinfo(2).func
    if(not _CONT[func]) then
        _CONT[func] = true
        addEvent(repeatContinue, delay, func, delay, n, ...)
    end
end

function repeatContinue(func, delay, n, ...)
    if(n > 1) then
        func(...)
        addEvent(repeatContinue, delay, func, delay, n - 1, ...)
    else
        _CONT[func] = nil
    end
end
Then here is example of usage (talkaction):
Lua:
function doThatShit(cid)
    if(not isCreature(cid)) then
        return
    end
   
    doCreatureSay(cid, "HiHO", 1)

    -- repeat 4 times (will only repeat 4 times because it count the current call as 1!) each second
    continue(1000, 5, cid)
end

function onSay(cid, words, param, channel)
    doThatShit(cid)
    return true
end
So all you have to do is to write continue(delay, repeatTimes, parameters) ! You don't need to write the function name, it will know that itself! You don't need any counter in your function, it will count itself!

A normal script WITHOUT this function would look like this:
Lua:
function doThatShit(cid, n)
    if(not isCreature(cid)) then
        return
    end
   
    doCreatureSay(cid, "HiHO", 1)

    if(n > 1) then
        addEvent(doThatShit, 1000, cid, n - 1)
    end
end

function onSay(cid, words, param, channel)
    doThatShit(cid, 5)
    return true
end
Not the greatest difference but surely saves you some thinking and time.


NOT WHAT YOU'RE LOOKING FOR?
Check this out: http://otland.net/f163/sleep-not-beds-20193/
 
Last edited:
Thats awesome! Glad to see you back and releasing things for the community again.
 
It's actually an old script but it was kinda hidden inside a tutorial so I had to make it its own thread!
 
Colandus, It looks like addEvent function! So I thought if I reload a script that is including your functions, does it cancel the function as it is doing in addEvent function? For example. I use addEvent function on a onUse script. Then when I reload actions, the addEvent suddenly cancels and doesn't count down the seconds. Does your functions do it too?
 
Yes of course. You're not supposed to reload when your server is running as all variables are reset and events cancelled which will affect lots of scripts in your server.
 
Back
Top