SixM
Single player ↗

Server API

sixm.red, al_cliente, jugadores, echar, commands, storage and exports: what only exists on the server.

In addition to the common API, a resource's server side has:

CallWhat it does
sixm.red(evento)lets clients send that event. Without this, the server drops it. The handler receives the sender's id first: sixm.on("x", function(id, ...) end)
sixm.al_cliente(id, evento, ...)event to one player (-1 = everyone)
sixm.jugadores()list of connected ids
sixm.jugador(id)the player's record (below) or nil
sixm.echar(id, motivo)removes them from the server with that reason
sixm.comando(nombre, fn)/name in the chat: fn(id, args, linea)
sixm.kvp.get(clave), sixm.kvp.set(clave, valor), sixm.kvp.borrar(clave), sixm.kvp.claves(prefijo)the resource's storage (Storage (KVP))
sixm.exporta(nombre, fn)offers a function to other resources on the server
sixm.importa(recurso).funcion(...)calls another resource's export
sixm.ahora()milliseconds since the server started

A player's record

sixm.jugador(id) returns:

FieldWhat it is
idtheir number on this server (changes on every connection)
nombrethe name they entered in the launcher
testigotheir identity (witness token): 16 hexadecimal digits, the same on every server (Administrators)
admintrue if their testigo is on an admin line of servidor.cfg
x, y, z, rumbowhere they are and which way they face (if they have already spawned)
saludtheir health
en_vehiculowhether they are in a vehicle

To store a player's data, use their testigo, not their id: the id changes every time they join.

sixm.on("jugador:entra", function(id)
  local j = sixm.jugador(id)
  local datos = sixm.kvp.get("jugador:" .. j.testigo) or { visitas = 0 }
  datos.visitas = datos.visitas + 1
  sixm.kvp.set("jugador:" .. j.testigo, datos)
end)

Commands

sixm.comando("dado", function(id, args, linea)
  local caras = tonumber(args[1]) or 6
  sixm.importa("sixm-base").decir(-1, sixm.jugador(id).nombre .. " saca un " .. math.random(caras))
end)
  • args: the words after the command (/dado 20 → { "20" }).
  • linea: the whole text as typed, for when you need the spaces.

Commands come from the chat (T, the one from sixm-base). A command does not check permissions on its own: do it yourself (sixm.jugador(id).admin or rp.es_admin(id)).

Exports

-- in the "banco" resource
sixm.exporta("saldo", function(testigo) return (sixm.kvp.get("saldo:" .. testigo) or 0) end)

-- in another resource
local banco = sixm.importa("banco")
print(banco.saldo("0123456789abcdef"))

More in Exports and commands.

Kicking

sixm.echar(id, "Fuera de rol")

The player receives the reason; the other resources receive jugador:sale(id, motivo).