SixM
Single player ↗

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_personajes per 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 },
    -- ...
  },
}
SettingWhat it does
max_personajescharacters per player (per testigo)
dinero_inicialcash and bank of a new character
peso_maxkilos carried; giving an item that doesn't fit fails
sueldo_cada_minhow many minutes between salary payments (to the bank) to those on duty, and the benefit to the unemployed
guardar_cada_show often each character's position is saved
zonawhere 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
adminstestigos with roleplay permissions, in addition to the admin lines of servidor.cfg
trabajoseach job with its ranks from lowest to highest and each one's salary. parado must exist
objetoseach 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.

ExportReturnsWhat it does
personaje(id)table or niltheir 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, bancotheir money (in JS, only the cash: use personaje(id))
dar_dinero(id, n, tipo, motivo)true/falseadds n (integer > 0) to "efectivo" or "banco" (any other tipo counts as cash)
quitar_dinero(id, n, tipo, motivo)true/falsesubtracts; fails if they don't have enough
transferir(de, a, n)true/falsebank to bank between two connected players
dar_objeto(id, objeto, n)true/falsefails if the item doesn't exist or doesn't fit
quitar_objeto(id, objeto, n)true/falsefails if they don't have that many
tiene(id, objeto)numberhow many they carry
objeto(nombre)table or nilthe item's record in Config.objetos
nombre_objeto(objeto, id)textthe item's name in that player's language (the id itself if it doesn't exist)
poner_trabajo(id, trabajo, rango)true/falsechanges job and rank (a number, 1 = the lowest; takes them off duty)
trabajo(id)trabajo, rango, de_serviciotheir current job
es_admin(id)true/falseroleplay 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)ArgumentsWhen
rp:personaje_listoid, nthe player has chosen a character and is now in the game
rp:usoid, objetothey 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

CommandWhoWhat it does
/yo (/whoami)everyoneyour id and your testigo
/dinero (/money)everyonecash and bank
/servicio (/duty)everyonego on or off duty
/dar_dinero <id> <cantidad> [efectivo|banco] (/give_money)admingives money
/trabajo <id> <trabajo> [rango] (/job)adminsets 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)admingives 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).