Storage (KVP)
sixm.kvp stores values and tables per resource, on the server, across restarts.
Each resource has its own key → value store on the server, which survives restarts. It lives in datos-servidor/kvp/<resource>.kvp. It only exists on the server side.
| Call | What it does |
|---|---|
sixm.kvp.get(clave) | the stored value, or nil (null in JS) |
sixm.kvp.set(clave, valor) | stores the value (string, number, boolean or table) |
sixm.kvp.borrar(clave) | deletes it |
sixm.kvp.claves(prefijo) | list of keys starting with prefijo (all of them, without it) |
Unlike FiveM, it stores whole tables, without converting them to JSON:
local pj = sixm.kvp.get("pj:12") or { nombre = "Nuevo", dinero = 0, inventario = {} }
pj.dinero = pj.dinero + 100
pj.inventario.agua = (pj.inventario.agua or 0) + 1
sixm.kvp.set("pj:12", pj)
for _, clave in ipairs(sixm.kvp.claves("pj:")) do
print(clave)
end
const h = sixm.kvp.get('historial') ?? [];
sixm.kvp.set('historial', [{ texto: 'hola', cuando: Date.now() }, ...h].slice(0, 20));
Good habits
- Prefixed keys by type:
pj:<n>,cuenta:<testigo>,tiendas. This wayclaves(prefijo)finds everything of one type. - Store by testigo (witness token), not by player id: the id changes on every connection; the testigo is always the same.
- Save when something important changes (money) and everything else every so often.
sixm-rpsaves the position every minute withsixm.cada. - Also save when the resource stops, with
recurso:para. - Each resource only sees its own data. To read another's, that other resource offers an export.
Backups
Copy datos-servidor/kvp/ with the server stopped (or from the panel, stopping it first). To start a resource from scratch, delete its .kvp with the server stopped.