Skip to content

World and server

Function
SetTimer(fn, ms, repeating)id fn runs after ms milliseconds — once, or every ms when repeating is true
KillTimer(id)

Timers run on the simulation thread, from OnTick’s slot: a timer’s function may call anything a callback may. A hot reload disposes them with the VM.

local heartbeat = SetTimer(function()
Log(GetPlayerCount() .. " player(s) online, tick " .. GetServerTick())
end, 300000, true)
SetTimer(function() SendClientMessageToAll(COLOUR_SERVER, "the round starts") end, 10000)

Every client follows the server’s clock.

Function
GetWorldTime()hours 13.5 = 13:30
SetWorldTime(hours) moves everyone’s clock
GetTimeRatio(), SetTimeRatio(r) game seconds per real second: 15 = the game’s own pace, 0 = frozen
FormatWorldTime([hours])"HH:MM" now, or the hours given
Function
GetRain(), SetRain(intensity) 0..1 forces rain on every client; -1 = the level’s own weather
GetWeather(), SetWeather(preset [, blendSeconds])bool the sky’s time-of-day profile, blended in over the seconds given ([world] weather_blend without them)
GetWeatherPresets(){preset = profile}

Presets: "clear", "fair", "cloudy", "overcast", "showers", "drizzle", "storm", "dry_storm" — or a level profile name as the level’s mission file has it ("foggy_storm"). The rain override is its own lever on top of the profile. [world] weather in server.toml sets the start.

Function
GetServerData(key), SetServerData(key, value) a server-wide key/value store for the mode (strings; nil removes), persisted in data/server.json

Per-name values are SetSavedData; values the clients should read are state bags.

Function
GetServerTick() the tick number
GetServerTime() milliseconds — the clock the protocol carries
GetMaxPlayers() the slots
GetLevel() the level’s name
GetDefaultSpawn()x, y, z, yaw [spawn] from server.toml
SetGameModeText(name) the mode’s name in the log and the server browser
ReloadGameMode([reason]) this very mode reloaded at the end of the tick — hot reload
Log(...) to the server log, prefixed [lua]; print is the same
COLOUR_SERVER, COLOUR_WHITE, COLOUR_RED, COLOUR_GREEN, COLOUR_YELLOW 0xRRGGBBAA
GAMETEXT_CENTRE, GAMETEXT_TOP, GAMETEXT_LOWER 0, 1, 2
HUD_ALIGN_LEFT, HUD_ALIGN_CENTRE, HUD_ALIGN_RIGHT 0, 1, 2
BODY_PART_HEAD, BODY_PART_TORSO, BODY_PART_ARM_LEFT, BODY_PART_ARM_RIGHT, BODY_PART_LEG_LEFT, BODY_PART_LEG_RIGHT 16
NO_TEAM -1
ENTITY_PLAYER, ENTITY_HORSE, ENTITY_ITEM, ENTITY_NPC, ENTITY_PROP, ENTITY_DOG 05, the kinds GetEntities(kind) takes