Docs/Getting started

Getting started

Write your first scenario: the folder layout, how scenarios are loaded and reloaded, and a working example.

API version 1Lua 5.1Updated 2026-11-07

These pages describe the scenario system of the rtv-mp dedicated server. They are published early so you can see what is possible. The API may still change, and hosting your own server is not available yet.

Scenarios are data files and Lua scripts that add rules to an rtv-mp server. Balance lives in data files such as loot.json; scripts are optional and add custom logic. This document covers every file a scenario can contain, everything a script can call, when its code runs, and what it is not allowed to do.

API version: 1 (server.api). The server runs gopher-lua, which implements Lua 5.1.

Quick start#

  1. Copy scenarios/example to scenarios/myserver. The scenarios folder sits next to server-settings.json.
  2. Set "scenario": "myserver" in server-settings.json and start the server. The log shows [scenario] loaded scenario=myserver ....
  3. Edit scenarios/myserver/init.lua and type /scenario reload in the server console, or in chat as an admin.
on("player_spawn", function(player, reason)
  if reason == "join" then
    player:tell("Welcome, " .. player.name)
  end
end)

command("online", function(player, args)
  player:tell(#server.players() .. " players online")
end)

register_event("ambush", {
  maps = {"Village"},
  chance = 20,
  duration = 600,
}, function(area, event)
  for i = 1, 3 do
    local position = area:random_position()
    if position then
      area:spawn_npc(position, "bandit")
    end
  end
  area:tell("You hear voices in the woods...")
end)

Folder layout and loading#

server-settings.json              "scenario": "myserver"   (empty = the scenario built into the binary)
scenarios/
  default/                        readable copy of the built-in scenario
  myserver/
    scenario.json                 optional: name, base, maps, start_area
    globals.json, world.json,     optional data files
    players.json, events.json,
    ai.json, loot.json,
    presets.json, economy.json
    zones/<Map>.json              optional zone data
    events/positions/<Map>.json   optional event positions
    init.lua                      optional script entry point
    lib/messages.lua              loaded with require("lib.messages")
data/scenarios/myserver.json      saved data written by store (not edited by hand)

Every file is optional, but the folder must exist. A scenario can be data only or scripts only. Data files and their layering are documented in docs/; this page covers the Lua side. The default scenario uses vanilla-style loot rolls; economy.json can opt into a count-based restock system.

  • Selecting a scenario. The scenario setting is a folder name: 1 to 64 letters, digits, _ or -. An empty or missing setting runs the built-in default scenario, which has no Lua; the log says [scenario] built-in default. The server looks for the folder next to the settings file passed with -settings.
  • Base chain. scenario.json base names the scenario to start from (default: the built-in default, always the copy inside the binary). Only the selected scenario's init.lua runs, never a base's. require looks in the selected folder first, then in each base folder on disk.
  • Startup. The server reads all data files and the saved data, then runs init.lua once, before it opens. If any of these fail (an invalid value, unreadable saved data, a script error, or more than 2 seconds of script work), the server does not start, as with an invalid setting.
  • What init.lua should do. Register hooks, commands and events, and set up module state. Areas are not loaded yet while it runs at startup; use the area_loaded hook for work that needs an area.
  • Reloading. /scenario reload reads every data file again, builds a new Lua state and runs init.lua again. If anything fails, the error is reported and the old scenario (data and scripts) keeps running unchanged. If it succeeds:
    • The new data applies from then on: loaded areas get the new globals.json rules at once, and new loot rolls, spawns, events and loadouts use the new files. Loot already in the world is not rerolled; use /respawnloot for that.
    • A changed base, maps, start_area or api_version in scenario.json is refused (restart the server); so is a changed world.json season.force (it is applied only when the world loads).
    • Saved data (store) is kept as it is.
    • The old state is dropped, along with all its waiting tasks, timers, running scenario events and module variables. Those events end without event_ended or cleanup. NPCs they spawned stay in the world.
    • Players and areas already online are recorded silently. No player_join, player_spawn or area_loaded fires for them again; use server.players() and server.areas() in init.lua if you need them.
    • Every scenario event's first roll is one interval after the reload.
    • The scenario setting itself is read only at startup. Switching to a different scenario folder needs a restart.

Reference

Lua runtime

API

API overviewNavigate the scenario Lua API by its global functions, commands, hooks, server, player, area, NPC, event, task and saved-data interfaces.Global functionsReference for scenario Lua functions: hooks, events, tasks, timers, modules and logging.Chat commandsRegister scenario chat commands and handle player and args parameters, command names, built-in conflicts and permissions.HooksEvery rtv-mp scenario hook, its arguments and when it fires: player_join, player_spawn, player_death, player_leave, area_loaded, npc_killed and event hooks.ServerThe server table in rtv-mp scenarios: server.players, server.area, server.broadcast, server.console, server.time and the other server-wide functions.PlayerFields and methods of a player handle in rtv-mp scenario scripts: name, identity, health, position, area, plus tell, give and teleport.AreasFields and methods of area handles: list players and NPCs, find positions, spawn NPCs, start and stop events, and send local messages.NPCsFields and methods of NPC handles in rtv-mp scenario scripts, including health, position, faction and kill.Object placementPlace and remove game prefabs and assets in Lua, with examples for houses, fences, rotation and ground snapping.EventsDefine custom events with register_event in rtv-mp scenarios: options, how chance rolling works, the event lifecycle, how events end, and event handles.Saved data (store)The store table in rtv-mp scenarios: key-value data that survives reloads and server restarts, with the rules for keys and values and the size limits.Tasks and timersInspect and cancel task handles created by spawn, after and every in scenario scripts.

Guides

JSON

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