GlobalEvents

onStartUp()

onStartup has no parameters, requires no return, and only runs once during the start of the server.
Example startup.lua
1
function onStartup()
2
print("There are " ..#Game.getHouses().. " houses registered to this map")
3
end
Copied!
You can register in data/globalevents/globalevents.xml by using type="startup" like so:
1
<globalevent type="startup" name="ServerStartup" script="startup.lua" />
Copied!

onShutdown()

onShutdown has no parameters, requires no return, and only runs once during the shutdown of the server
Example shutdown.lua
1
function onShutdown()
2
for index, player in pairs(Game.getPlayers()) do
3
player:save()
4
end
5
end
Copied!
You can register in data/globalevents/globalevents.xml by using type="shutdown" like so:
1
<globalevent type="shutdown" name="ServerShutdown" script="shutdown.lua" />
Copied!

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
1
function onRecord(current, old)
2
addEvent(Game.broadcastMessage, 150, "New record: " .. current .. " players are logged in.", MESSAGE_STATUS_DEFAULT)
3
return true
4
end
Copied!
You can register in data/globalevents/globalevents.xml by using type="record" like so:
1
<globalevent type="record" name="PlayerRecord" script="record.lua" />
Copied!

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
1
function onTime(interval)
2
Game.startRaid("Dragons")
3
return true
4
end
Copied!
You can register in data/globalevents/globalevents.xml by giving it a unique name and setting the time using time="time" like so:
1
<globalevent name="StartDragonRaid" time="09:55:00" script="ontime.lua" />
Copied!

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
1
function onThink(interval)
2
for index, player in pairs(Game.getPlayers()) do
3
player:save()
4
end
5
return true
6
end
Copied!
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
1
<globalevent name="SaveOnThink" interval="10000" script="onthink.lua" />
Copied!
The above will execute every ten seconds 10 * 1000 = 10000