• 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 Globalevents without interval

v[GOD]

New Member
Joined
Jun 15, 2018
Messages
10
Reaction score
1
Is it possible to set a direct interval in the script?

And remove the interval from the globalevent tag thus:

<globalevent event = "script" value = "save.lua" />
 
Yes use addEvent. If you need to call it again and again then make a recursive function.
Example
Lua:
function myRecursiveFunction(time,  ...)
    print(...)
    addEvent(myRecursiveFunction, time, time, ...)
end

myRecursiveFunction(2 * 1000 * 60, "this function will execute every 2 minutes forever or until you shutdown the server ;)")
Just don't tie it to anything that can crash the server.
 
Last edited:
I did so will it work?
Code:
local h = os.time()
local last = h
local int = 60*60*1 -- in seconds
local advertisement = math.random(1, 10)
function onThink(interval, lastExecution)
    if (last + int) < h then
        last = h

        if advertisement == 1 then
            broadcastMessage("testing", MESSAGE_EVENT_ADVANCE)
            advertisement = 2
        elseif advertisement == 2 then
            broadcastMessage("testing", MESSAGE_EVENT_ADVANCE)
            advertisement = 1
        end
        -- keep putting the two to test

    end

    h = os.time()

    return true
end
Tag:
Code:
<globalevent name="script" interval="" event="script" value="script.lua"/>
 
Here is another way you can emulate addEvent although the precision of time will fluctuate.
Lua:
function addEvent(f, t, ...)
    local nTime = os.time() + t
    repeat until os.time() >= nTime
    return f(...)
end

addEvent(print, 3, "This is a test")

Output
Lua:
This is a test
Program completed in 3.21 seconds (pid: 4077).

This is bad tho because it might just hang the server.
 
the interval per default of the function
Code:
addEvent(callback, delay, ...)
is 100 milliseconds.
Code:
uint32_t delay = std::max<uint32_t>(100, getNumber<uint32_t>(globalState, 2));
It would be much better if you told us what you want to do with this?
 
the interval per default of the function
Code:
addEvent(callback, delay, ...)
is 100 milliseconds.
Code:
uint32_t delay = std::max<uint32_t>(100, getNumber<uint32_t>(globalState, 2));
It would be much better if you told us what you want to do with this?

It is a script of automatic messages that when a message is sent when the given time does not send the same message but yes next to if

I know there are several ready, but I wanted to create mine for both a server and for learning ...
 
The messages will go to the whole server.

Example of script operation:

Message talking about something ...

after the time interval, the script will check which message was sent and then send it next to the list

I do not know if it was well explained, I'm bad with English, sorry.
 
Back
Top