Exports and commands
Functions a resource offers to others (also from Lua to JS) and chat commands starting with /.
Exports
An export is a server function that one resource offers to the others. Everything is built on top of sixm-rp this way: stores don't touch the money, they call quitar_dinero (remove money).
-- "multas" resource, servidor.lua
sixm.exporta("multar", function(id, cantidad, motivo)
local rp = sixm.importa("sixm-rp")
return rp.quitar_dinero(id, cantidad, "banco", "multa: " .. motivo)
end)
-- another resource
local multas = sixm.importa("multas")
if multas.multar(3, 150, "exceso de velocidad") then print("multado") end
sixm.importa(nombre)returns an object with that resource's exports. The resource must be running: put it independe.- It works across languages: a JS resource imports a Lua one and vice versa.
- In Lua, an export can return several values (
return efectivo, banco). From JS you receive the first one. - In JS, an export cannot be
async. - Exports are server-only. On the client, resources talk to each other with
sixm.emitir. - Arguments and results are the same types as in events: no functions.
The bundled exports
sixm-base
| Export | What it does |
|---|---|
avisar(id, texto, tipo) | notice at the top right; type bien (good), error, info or dinero (money). id -1 = everyone. texto can be { en = "...", es = "..." }: each player gets their language |
decir(id, texto) | system line in the chat. id -1 = everyone. texto can also be { en = "...", es = "..." } |
nombre(id) | the player's name (or #id) |
idioma(id) | the player's language: "en" or "es" ("en" until their client has reported it; the event sixm:idioma_listo fires when it does) |
sixm-rp: characters, money, items and jobs (including nombre_objeto(objeto, id)). Full list in Roleplay framework.
npcs
| Export | What it does |
|---|---|
poner({ x, y, z, rumbo, modelo, modo, nombre }) | adds a fixed NPC (modo is quieto (still) or pasea (wanders); modelo 0 = the model of the player who sees it). Returns its number |
quitar(n) | removes the NPC with that number |
Commands
sixm.comando("me", function(id, args, linea)
local base = sixm.importa("sixm-base")
base.decir(-1, "* " .. base.nombre(id) .. " " .. table.concat(args, " "))
end)
sixm.comando('me', (id, args) => {
const base = sixm.importa('sixm-base');
base.decir(-1, `* ${base.nombre(id)} ${args.join(' ')}`);
});
- The player types it in the chat (T) with
/:/me se rasca la cabeza. fn(id, args, linea): who, the words after the command and the whole line.- Commands are server-side. To check permissions:
sixm.jugador(id).adminorsixm.importa("sixm-rp").es_admin(id). sixm-base's/ayuda(help) says that each resource adds its own: list them in your own help message if there are many.
Commands that already exist
| Command | English alias | Resource |
|---|---|---|
/ayuda, /jugadores, /pos | /help, /players | sixm-base |
/yo, /dinero, /servicio | /whoami, /money, /duty | sixm-rp |
/dar_dinero, /trabajo, /dar_objeto (admin) | /give_money, /job, /give_item | sixm-rp |
/tienda_aqui, /tienda_quitar (admin) | /shop_here, /shop_remove | tiendas |
/npc_aqui, /npc_quitar (admin) | /npc_here, /npc_remove | npcs |
/e, /fantasma (test) | /ghost | gestos |
/personaje | /character | aspecto |
/anuncio, /anuncios (/anuncio admin) | /announce, /announcements | anuncios |
/guiones, /parar | /scripts, /stopscript | vaciar (only with pruebas = true; open to every player) |
/pos gives your location exactly as it goes in servidor.cfg: aparicion x y z rumbo.