Docs/API

Global functions

Reference for scenario Lua functions: hooks, events, tasks, timers, modules and logging.

API version 1Lua 5.1Updated 2026-11-07

on(hook, function)#

Adds a handler for a hook. A hook can have several handlers; they run in the order they were added, each as its own task. Unknown hook names raise an error at load.

register_event(name, [options,] function(area, event))#

Defines a scenario event.

spawn(function, ...)#

Starts function(...) as a new task once the calling code pauses or returns (see when code runs) and returns a task handle. Raises an error when 1024 tasks are already alive.

wait([seconds])#

Pauses the current task for seconds (default 0, which means the next tick), from 0 to 10,000,000. Raises an error when called outside a task, which includes code at the top level of init.lua.

after(seconds, function, ...)#

Runs function(...) once after seconds. Returns a task handle; cancel it to call it off.

every(seconds, function)#

Runs function() every seconds (which must be greater than 0) until cancelled. Returns a task handle. If the function fails, the loop ends.

require(name)#

Loads <scenario>/<name with dots as slashes>.lua, runs it once and returns its result: require("lib.messages") loads lib/messages.lua. A module that returns nothing yields true. Later calls return the cached value. Names may only contain letters, digits, _ and ., so a module cannot reach outside the folder. Circular requires raise an error.

print(...)#

Converts each argument with tostring, joins them with tabs and writes [scenario] <text> to the server log. server.log(...) does the same.

Found a mistake or missing detail? Tell us in the Discord.