Roleplay framework (sixm-rp)
Characters, cash and bank money, jobs with ranks and salary, inventory with weight and the roleplay zone.
sixm-rp is the roleplay core, like ESX or QBCore in FiveM: it stores each player's characters with their money, job and inventory, and offers exports so that other resources (stores, phone, your own) don't touch that data directly.
local rp = sixm.importa("sixm-rp")
It depends on sixm-base. Everything is adjusted in recursos/sixm-rp/config.lua.
What the player sees
- On joining: choose or create a character (first name, last names, date of birth). Up to
max_personajesper player. - I: inventory, with weight. Items with
salud(health) can be used (food, bandages) and any item can be dropped. - A HUD with money, job and whether they are on duty.
/dinero(money),/servicio(go on or off duty) and/yo.- When they come back, they appear where they left off (if they were inside the roleplay zone).
Configuration
Config = {
max_personajes = 4,
dinero_inicial = { efectivo = 500, banco = 2500 },
peso_max = 30, -- kg a character carries
sueldo_cada_min = 15, -- how often those on duty get paid
guardar_cada_s = 60, -- position and health
zona = { nombre = "My town", x_min = 0, x_max = 1000, y_min = 0, y_max = 1000, aviso_s = 8 }, -- bounds read with /pos
admins = { }, -- testigos with roleplay permissions (in addition to the "admin" lines of servidor.cfg)
trabajos = {
parado = { nombre = { en = "Unemployed", es = "Sin trabajo" }, rangos = { { nombre = { en = "Jobless", es = "Parado" }, sueldo = 50 } } },
policia = { nombre = { en = "Police", es = "Policía" }, rangos = {
{ nombre = { en = "Cadet", es = "Cadete" }, sueldo = 300 }, { nombre = { en = "Officer", es = "Agente" }, sueldo = 450 } } },
-- medico, mecanico, taxista...
},
objetos = {
agua = { nombre = { en = "Water", es = "Agua" }, peso = 0.5, salud = 5 },
venda = { nombre = { en = "Bandage", es = "Venda" }, peso = 0.1, salud = 25 },
telefono = { nombre = { en = "Phone", es = "Teléfono" }, peso = 0.2 },
-- ...
},
}
| Setting | What it does |
|---|---|
max_personajes | characters per player (per testigo) |
dinero_inicial | cash and bank of a new character |
peso_max | kilos carried; giving an item that doesn't fit fails |
sueldo_cada_min | how many minutes between salary payments (to the bank) to those on duty, and the benefit to the unemployed |
guardar_cada_s | how often each character's position is saved |
zona | where the roleplay takes place. Anyone who leaves has aviso_s seconds to come back or is returned (with their car) to the last place inside. nil = the whole map |
admins | testigos with roleplay permissions, in addition to the admin lines of servidor.cfg |
trabajos | each job with its ranks from lowest to highest and each one's salary. parado must exist |
objetos | each item with its weight in kg; those with salud can be used and heal that amount |
Every nombre (job, rank, item) can be a plain text or { en = "...", es = "..." }: each player sees it in their language. The keys (policia, agua...) are the ids that exports and commands use, and they are not translated.
By default the roleplay takes place in one town, while the rest of the map stabilizes. It ships with the jobs parado (unemployed), policia, medico, mecanico and taxista, and the items agua, pan, bocadillo, venda, telefono, linterna and ganzua. A new character starts with 2 water, 2 bread and a phone.
Exports
All are server-side. id is the player's id; they work on the character the player is currently using.
| Export | Returns | What it does |
|---|---|---|
personaje(id) | table or nil | their data: personaje (number), nombre, apellidos, efectivo, banco, trabajo and rango (names in the player's language), trabajo_id, sueldo, idioma ("en" or "es"), servicio, inventario, peso, peso_max |
dinero(id) | efectivo, banco | their money (in JS, only the cash: use personaje(id)) |
dar_dinero(id, n, tipo, motivo) | true/false | adds n (integer > 0) to "efectivo" or "banco" (any other tipo counts as cash) |
quitar_dinero(id, n, tipo, motivo) | true/false | subtracts; fails if they don't have enough |
transferir(de, a, n) | true/false | bank to bank between two connected players |
dar_objeto(id, objeto, n) | true/false | fails if the item doesn't exist or doesn't fit |
quitar_objeto(id, objeto, n) | true/false | fails if they don't have that many |
tiene(id, objeto) | number | how many they carry |
objeto(nombre) | table or nil | the item's record in Config.objetos |
nombre_objeto(objeto, id) | text | the item's name in that player's language (the id itself if it doesn't exist) |
poner_trabajo(id, trabajo, rango) | true/false | changes job and rank (a number, 1 = the lowest; takes them off duty) |
trabajo(id) | trabajo, rango, de_servicio | their current job |
es_admin(id) | true/false | roleplay administrator |
Every money movement is logged with its motivo (reason; the last 50 per character): always provide one.
local rp = sixm.importa("sixm-rp")
local base = sixm.importa("sixm-base")
sixm.red("taller:reparar")
sixm.on("taller:reparar", function(id)
local trabajo, rango, servicio = rp.trabajo(id)
if trabajo ~= "mecanico" or not servicio then
return base.avisar(id, "Solo mecánicos de servicio", "error")
end
if not rp.quitar_objeto(id, "llave_inglesa", 1) then
return base.avisar(id, "Te falta una llave inglesa", "error")
end
rp.dar_dinero(id, 80, "banco", "reparación")
end)
For a new item such as llave_inglesa, add it to Config.objetos.
Events
| Event (server) | Arguments | When |
|---|---|---|
rp:personaje_listo | id, n | the player has chosen a character and is now in the game |
rp:uso | id, objeto | they used an inventory item (after it has been removed from them) |
sixm.on("rp:uso", function(id, objeto)
if objeto == "linterna" then sixm.al_cliente(id, "linterna:encender") end
end)
For an item without salud to be usable, give it salud = 0 in Config.objetos and react to rp:uso.
Commands
| Command | Who | What it does |
|---|---|---|
/yo (/whoami) | everyone | your id and your testigo |
/dinero (/money) | everyone | cash and bank |
/servicio (/duty) | everyone | go on or off duty |
/dar_dinero <id> <cantidad> [efectivo|banco] (/give_money) | admin | gives money |
/trabajo <id> <trabajo> [rango] (/job) | admin | sets a job; trabajo is the internal id: parado, policia, medico, mecanico or taxista; rango is a number (1 = the lowest) |
/dar_objeto <id> <objeto> [cantidad] (/give_item) | admin | gives an item |
Where it is stored
In sixm-rp's KVP: cuenta:<testigo> (each player's characters), pj:<n> (each character), mov:<n> (their movements) and sig_pj (the next number). Other resources store their own data by character number (aspecto, telefono).