A resource is a folder in resources/ with a resource.lua manifest:
resources/hello/ resource.lua server/main.lua client/main.lua
-- resource.lua
description "Hello, world"
server_scripts { "server/main.lua" }
client_scripts { "client/main.lua" }
files { "client/ui" } -- folders and files for pages (optional)
-- server/main.lua
events.on("playerReady", function(player)
player:setMoney(100)
player:emit("hello:welcome", player.name)
end)
-- client/main.lua
events.onServer("hello:welcome", function(name)
print("The server said hello to " .. name)
end)
Add the resource to [resources] start=basic-rp,hello and restart the server.
Rules
- Each resource runs in its own Lua: global variables don't clash.
- Resources talk through events:
events.emiton the server,events.emiton the client. - Only data travels between server and client: nil, boolean, number, string and tables.
- Check everything that comes from a client on the server.
- Script errors go to the server console and to the player's
m2o_client.log.