GlobalEvents

onStartUp()

onStartup has no parameters, requires no return, and only runs once during the start of the server.

Example startup.lua

function onStartup()
    print("There are " ..#Game.getHouses().. " houses registered to this map")
end

You can register in data/globalevents/globalevents.xml by using type="startup" like so:

<globalevent type="startup" name="ServerStartup" script="startup.lua" />

onShutdown()

onShutdown has no parameters, requires no return, and only runs once during the shutdown of the server

Example shutdown.lua

function onShutdown()
    for index, player in pairs(Game.getPlayers()) do
        player:save()
    end
end

You can register in data/globalevents/globalevents.xml by using type="shutdown" like so:

<globalevent type="shutdown" name="ServerShutdown" script="shutdown.lua" />

onRecord(current, old)

onRecord has two parameters, requires return true, and runs each time a new record is made for most players online

  • current -- number value of new record, for most players online

  • old -- number value of old record, for most players online

Example record.lua

function onRecord(current, old)
    addEvent(Game.broadcastMessage, 150, "New record: " .. current .. " players are logged in.", MESSAGE_STATUS_DEFAULT)
    return true
end

You can register in data/globalevents/globalevents.xml by using type="record" like so:

<globalevent type="record" name="PlayerRecord" script="record.lua" />

onTime()

onTime has one parameter which represents the time it executes, requires return true, and runs each each day at same time

Example ontime.lua

function onTime(interval)
    Game.startRaid("Dragons")
    return true
end

You can register in data/globalevents/globalevents.xml by giving it a unique name and setting the time using time="time" like so:

<globalevent name="StartDragonRaid" time="09:55:00" script="ontime.lua" />

onThink()

onThink has one parameter which represents how often it executes in milliseconds, requires return true, and runs as often as specified in globalevents.xml

Example onthink.lua

function onThink(interval)
    for index, player in pairs(Game.getPlayers()) do
        player:save()
    end
    return true
end

You can register in data/globalevents/globalevents.xml by giving it a unique name and setting how often it will execute using interval="1000" time is in milliseconds

<globalevent name="SaveOnThink" interval="10000" script="onthink.lua" />

The above will execute every ten seconds 10 * 1000 = 10000

Last updated