Docs/API

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.

API version 1Lua 5.1Updated 2026-11-07

store is a key-value table saved to data/scenarios/<scenario>.json. It survives /scenario reload and server restarts, so it suits leaderboards, unlocks, counters and any state that must outlast a session. Ordinary Lua variables reset on every reload and restart.

store.get(key)#

Returns: value or nil

A copy of the saved value. Changing the copy changes nothing until you store.set it again.

store.set(key, value)#

Returns: —

Saves a copy of value. nil deletes the key.

store.delete(key)#

Returns: —

Deletes the key.

store.keys([prefix])#

Returns: list of strings

Saved keys starting with prefix (default: all), sorted.

store.increment(key, [by])#

Returns: number

Adds by (default 1) to a number, treating a missing key as 0, and returns the new value. Raises an error if the key holds something other than a number.

  • Keys are strings of 1 to 200 bytes. A prefix per kind of data keeps them tidy and listable: "kills:" .. player.identity, "unlock:sniper:" .. player.identity.
  • Values must be plain data:
    • nil, booleans, finite numbers and strings;
    • lists (keys 1..n without gaps);
    • tables with only string keys, nested up to 32 levels.
  • Not storable: handles (players, areas, NPCs, events, tasks), functions, and tables that mix list entries with string keys. Store a player's identity or an area's key instead of the handle. A value that can't be stored raises an error and leaves the key unchanged.
  • Size: one value may be up to 256 KB of JSON, and all data together up to 4 MB.
  • Saving: changes are written in the background within about 5 seconds and again at shutdown. A crash can lose the last few seconds of changes, never the whole file.
  • Corruption: if the saved file is unreadable, the server refuses to start rather than overwrite it. Fix or move the file.
  • Separate from characters: the data belongs to the scenario. Switching to another scenario uses a different file; deleting the file resets the scenario's data without touching characters.
on("npc_killed", function(npc, killer)
  if killer and killer.identity then
    local total = store.increment("kills:" .. killer.identity)
    if total % 100 == 0 then
      server.broadcast(killer.name .. " reached " .. total .. " kills")
    end
  end
end)

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