OTS Guide
  • Introduction
  • Compiling
    • Compile on Arch
    • Compiling on CentOS
    • Compiling on Debian GNU Linux
    • Compiling on Fedora
    • Compiling on FreeBSD
    • Compiling on Gentoo
    • Compiling on Mac OS X
    • Compiling on Ubuntu
    • Compiling on Windows
    • Compiling on Windows (vcpkg)
  • Running your first OT Server
    • Setting up your first server
    • Connecting to your server
    • Editing your datapack
    • Opening your server to the public
  • TFS documentation
    • TFS 1.4 official release
    • LuaScript Interface
      • Action
      • ChatChannel
      • CreatureEvent
      • GlobalEvents
      • MoveEvent
    • Lua functions
    • Metatables
      • Game
  • Glossary
  • Running your first ubuntu linux OT
Powered by GitBook
On this page
  • onStartUp()
  • onShutdown()
  • onRecord(current, old)
  • onTime()
  • onThink()

Was this helpful?

  1. TFS documentation
  2. LuaScript Interface

GlobalEvents

PreviousCreatureEventNextMoveEvent

Last updated 3 years ago

Was this helpful?

  • ()

  • ()

  • (current, old)

  • (interval)

  • (interval)

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

onStartup
onShutdown
onRecord
onTime
onThink