Events
events.on
Subscribes a function to a server event: a built-in one or one from another resource.
events.emit
Fires an event in all of the server's resources (events.on).
events.onClient
Receives an event that a player's client script sent with events.emitServer.
events.emitClient
Sends an event to the client scripts of one player or of everyone.
player:emit
An event for this player's client scripts. Same as events.emitClient(player, ...).
events.onServer
Receives an event from a server script (events.emitClient / player:emit).
events.emitServer
Sends an event to the server's scripts (events.onClient).
Players
players.all
All players on the server (an array of Player).
players.get
A player by id.
players.count
How many players are on the server.
player.id
The player's number on the server (a property). Freed when the player leaves.
player.name
The player's nickname from the launcher (a property).
player:isValid
Is the player still on the server? A Player object outlives the player leaving, but its methods stop doing anything.
player:setSkin
Changes the character's model. Everyone sees it.
player:getSkin
The player's current model ("" is the default model).
player:setAppearance
Dresses the player as one of MafiaM's characters with its shape sliders. Everyone sees it.
player:getAppearance
The player's model and its shape sliders (an empty table for a plain model).
characters.models
MafiaM's characters: { {name, gender, body, about}, ... }. gender: "male" or "female" for one kind only.
characters.sliders
The shape sliders by group: { face = {...}, body = {...}, legs = {...} }, each { id, name, gender }.
characters.skin
A look as a skin string: characters.skin("MP_H007", { nw = 40 }) → "MP_H007+nw=40". characters.parse(skin) gives the model and sliders back.
characters.preview
Tries a look on in this player's game only (an appearance editor's window); endPreview brings back the skin the server gave.
player:setPosition
Teleports the player.
player:getPosition
Where the player is now (updated 20 times a second). nil until they are in the world.
player:kick
Disconnects the player with a message.
player:hasPermission
Does the player's group have this permission? Groups and their permissions are in m2o_server.ini ([groups] moderator = kick, players; admin = *), players get them by name from [admins] or from your mode: player:setGroup("admin") (e.g. after an account login), player:getGroup().
player:setDimension
Puts the player in a dimension (FiveM's routing buckets): players and vehicles only see those in the same one. 0 = the shared world.
player:getDimension
The player's dimension.
player:setDiscordPresence
One player's own Discord status (the same fields); nil = back to the world's.
players.getByName
A player by nickname (any case), or nil. Client scripts also have players.all() (ids), players.getName(id), players.isStreamed(id), players.getPosition(id).
player:getPing
The round trip to the player, in milliseconds.
player:getMoveMode
How the player moves: "stand", "walk", "run", "sprint", or "vehicle" when in one.
player:isInVehicle
Whether the player sits in a vehicle (player:getVehicle() gives which).
player:setFightStyle
The player's fist-fight style, for everyone: "KugnfuStyle", "HeavyStyle", "LightStyle" ("" = the normal one).
player:getAddress
The player's IP address.
player:getLicense
Who the player is, whatever name they play under: 40 hex digits, the same on every server and every time they come back.
player:getSteamId
The SteamID64 of the Steam account logged in on the player's PC, "" if Steam wasn't running.
player:setControlStyle
What the player's controls allow: no shooting, walking only, fists only... Only that player; stays after respawning. "" = everything.
player:getControlStyle
The player's control style ("" = everything allowed).
Money
player:setMoney
Sets the player's money (in the game, the character's cash).
player:giveMoney
Adds money (or takes it away, if negative).
player:getMoney
The player's money in dollars.
World
world.setTraffic
Turns cars and pedestrians on or off for all players.
world.setPolice
Police and wanted levels. Off: there are no police officers and crimes don't make you wanted.
world.getSeason
"summer" (the 50s) or "winter" (the 40s). Set in m2o_server.ini.
world.setWeather
Weather and time of day for everyone: one of the game's weather templates.
world.getWeather
The weather template set with setWeather.
world.setTime
The time of day for everyone: the city's light, the sky, the street lamps. It keeps running at the time scale.
world.getTime
The time of day now; nil if setTime wasn't used (the games keep their own).
world.setTimeScale
How fast the day goes: game minutes in a real minute. 1 = real time (default), 30 = a whole day in 48 minutes, 0 = the clock stands still.
world.getTimeScale
Game minutes in a real minute (see setTimeScale).
world.getTime
The time of day this player sees (the server's, or their own setLocalTime); nil if nobody set it.
world.setLocalTime
A time of day for this player only, for example inside a building or in a dream; setLocalTime(nil) gives them the server's again.
world.setNameTags
Names over players' heads (on by default).
world.setHealthBars
Health bars under the names.
world.setInteriors
The city's interiors - shops, bars, diners, apartments, garages: "free" (the default) - their doors open for anyone and nobody runs them: no shopkeepers, no shop menus, no tills to rob; use them as your mode likes. "closed" - shut. "game" - as in single player (shopkeepers, buying, robberies). world.getInteriors() tells the mode.
world.addPassage
A passage: at its entrance (from, within radius - 1.2 m by default) the player presses its key ("E" by default) - or, with key = false, just walks in - the screen fades and they come out at `to`, facing heading (radians). The hint ("[E] text") shows over the entrance. It's the player's own game that takes them through, at once; the server hears of it in "playerPassage". world.removePassage(id).
world.setDoorLocked
Locks (true) or unlocks (false) the city's door nearest to that spot (within 1.5 m) for every player: locked, nobody opens or kicks it in; unlocked, it opens even when the interiors are "closed". world.resetDoor(x, y, z) leaves it to the interiors mode again, world.isDoorLocked(x, y, z) → true / false / nil.
world.getNearestDoor
The city's door nearest to a point (within radius, 3 m by default): where it is and whether it's locked; nil if there's none. A shop's, a bar's, an apartment's - those of the interiors the game has loaded around you.
world.setWalkByDefault
On foot players walk; a quick tap on Shift switches to a jog and back, holding Shift sprints. On by default; false = the game's own controls (always jogging).
world.setDiscordPresence
What players' Discord shows while they play here (Rich Presence): details, state, largeImage, largeText, smallImage, smallText, buttons (up to 2 {label, url}), appId (your own Discord application; default: MafiaM's). {server}, {players}, {maxPlayers}, {name} are filled in.
physics.raycast
What a ray from one point to another hits first (the game's physics: walls, ground, cars, people). entity is "player" or "vehicle" with its id when it hit one.
Objects
objects.create
Places one of the game's props (a barrel, a crate, a sign...) that every player near it sees.
objects.get
An object by its id.
objects.all
All the server's objects.
object:setPosition
Moves the object for everyone.
object:getPosition
Where the object is (as placed by scripts: a player knocking it over doesn't change it).
object:setRotation
Turns the object: heading about the vertical axis, then pitch and roll; radians.
object:getRotation
The rotation the object was given.
object:setDimension
Shows the object only to players in that dimension (0 = everyone's usual world).
object:destroy
Removes the object for everyone. object:isValid() is false afterwards.
Vehicles
vehicles.create
Creates a car all players see. The driver controls it, everyone else sees it move.
vehicles.all
All of the server's cars.
vehicles.get
A car by id.
vehicle:getDriver
Who is driving (seat 0).
vehicle:getOccupants
Everyone in the car: a table seat → player (0 is the driver).
vehicle:getPassengers
The passengers (everyone but the driver).
vehicle:getPosition
Where the car is (as its driver reports).
vehicle:setPosition
Moves the car (for everyone, the driver included).
vehicle:destroy
Removes the car for everyone.
player:getVehicle
Which of the server's cars the player is sitting in.
player:getVehicleSeat
The player's seat in the car: 0 is the driver, 1 and up are passengers.
player:isDriver
Is the player driving one of the server's cars?
vehicle:setDimension
Puts a vehicle in a dimension: only players in the same one see it.
vehicle:getDimension
The vehicle's dimension.
player:warpIntoVehicle
Seats the player at once, no walk or animation (seat 0 = driver). player:putInVehicle(vehicle, seat, atOnce) walks to the door unless atOnce.
vehicle:getFreeSeats
The free seats (0 = driver). Also vehicle:getSeatCount() and vehicle:isSeatFree(seat). nil until a player's game has shown that model.
vehicle:setHandling
Changes this car's handling (mass, engine, gears, suspension, brakes...) at once, while it drives too. Only the fields given change.
vehicle:getHandling
All the car's handling fields: its model's (cars.json) with what setHandling changed over them.
vehicle:resetHandling
The car's handling back to its model's.
vehicles.getModelHandling
A car model's own handling (from cars.json next to the server).
vehicles.getModelInfo
A car model's name and paint jobs: { model, name, colors = { {code, primary, secondary}, ... }, ... }.
vehicle:setPlate
The vehicle's number plate, for everyone (6 characters, like "M2O-77").
vehicle:getPlate
The plate set with setPlate (nil: the game's own).
vehicle:setColor
Paints the vehicle, for everyone: a colour of the game's palette (numbers from 0); a second colour makes it two-tone.
vehicle:setEngine
Starts or stops the engine, for everyone.
vehicle:setBeacon
The beacon lights (police, ambulance...), for everyone.
vehicle:setSiren
The siren, for everyone.
vehicle:setHorn
Holds the horn, for everyone.
vehicle:setDirt
How dirty it is, 0 (clean) to 1, for everyone.
vehicle:setFuel
Fuel in the tank, for everyone.
vehicle:setLocked
Locks the doors (nobody gets in), for everyone.
vehicle:setHoodOpen
Opens / closes the hood, for everyone.
vehicle:setTrunkOpen
Opens / closes the trunk, for everyone.
vehicle:setSpeedLimit
A speed limiter, for everyone; nil takes it off.
vehicle:repair
Repairs and cleans the vehicle, for everyone.
vehicle:explode
Blows the vehicle up, for everyone.
vehicle:getSpeed
How fast it goes (from its driver's game).
vehicle:getVelocity
Its velocity, meters per second.
vehicle:setPaint
Two-tone paint: two colours of the game's palette (the same as setColor with two). For everyone.
vehicle:setTuning
Engine tuning, as in the game's garage (the model's tuning table). For everyone.
vehicle:setWheel
The wheels of an axle (0 = front pair, 1 = rear pair) to another wheel model - one the game has loaded, i.e. on some car nearby (wheel_civ02, wheel_civ04..09, wheel_univers_d / _n / _s, wheel_truckciv01 / 02). For everyone.
vehicle:setTyre
One tyre (0..3). For everyone.
vehicle:setWindowOpen
Rolls a seat's window down / up (0 = driver). For everyone.
vehicle:setDoorUnlatched
The door's latch lets go: it opens a little and swings as the car moves (0 = the driver's). For everyone.
vehicle:setBusDoorsOpen
A bus's doors. For everyone.
vehicle:setTrunkLocked
Locks the trunk. For everyone.
vehicle:setPartRemoved
Takes a part off (doors, hood, bumpers... by the model's part number) or puts it back. For everyone.
vehicle:setHeadlightsOff
Keeps the headlights off. For everyone.
vehicle:setBodyDamage
Body damage, in the game's units. For everyone.
vehicle:setEngineDamage
Engine damage, in the game's units (smoke, stalling). For everyone.
vehicle:setExplosionProof
The vehicle doesn't blow up. For everyone.
vehicle:setTyresProof
Bulletproof tyres. For everyone.
vehicle:setDamageResistance
How much damage it takes (the game's resistance). For everyone.
vehicle:setFrozen
Holds the vehicle where it is (a showroom...). For everyone.
vehicle:setRadio
The radio: a station of the game (names not found yet), on / off. For everyone.
vehicle:attachTo
Links the vehicle to another one (the game's LinkToEntity: towing...). detach() undoes it. For everyone.
vehicle:detach
Unlinks the vehicle. For everyone.
vehicle:revEngine
The rev-up effect (sound and engine shake); false stops it. For everyone.
vehicle:playAnimation
One of the vehicle's own animations (a convertible's roof...). For everyone.
vehicle:stopAnimation
Stops it. For everyone.
vehicle:getNative
What the server set under a key ("plate", "color", "window0"...), or nil.
vehicle:callNative
Calls one of the game's own functions (see the Natives page, C_WrapperCar) on this vehicle in everyone's game who sees it, once.
vehicle:setNative
Like callNative, but kept under key: whoever comes near later gets it too, and it's applied again if the game re-creates the vehicle. clearNative(key) forgets it.
vehicle:clearNative
Forgets a native kept with setNative (what it did stays until something changes it).
Data
storage.get
Reads a value from the resource's storage (data/<resource>.json).
storage.set
Saves a value (tables as a whole). nil deletes the key. Written to disk right away.
storage.keys
All keys of the resource's storage.
db.query
Runs SQL on the resource's database: SQLite (data/<resource>.db) by default, or MySQL / MariaDB with [database] mysql=mysql://user:password@host:3306/db in m2o_server.ini (same API). Off the server's thread: the answer comes to the function. Values go in place of ? - never glue SQL from players' text.
http.request
An HTTP(S) request to a host the server owner allows ([http] allow in m2o_server.ini; none by default). A table as body goes as JSON. Also http.get(url, cb, headers) and http.post(url, body, cb, headers); http.await.get / post / request inside async.
json.encode
Tables to JSON text and back.
security.hash
SHA-256 of a string (hex). Add a salt for passwords.
security.randomString
A random string of letters and digits (cryptographically secure).
settings.get
A setting from [settings] in m2o_server.ini (the server owner's).
Resources
exports
Functions one resource offers the others: a bank exports getMoney, every other resource calls exports.bank:getMoney(player). Values are copied (numbers, text, tables, players, vehicles, NPCs; not functions). A missing resource or function is an error (pcall catches it).
resources.restart
Starts, stops or restarts a resource at the next tick (a resource may restart itself). Stopping takes away what it made: vehicles, NPCs, blips, labels, timers, commands, its database connection; players' games reload its client part. Also resources.isRunning(name), resources.all(). The console has start / stop / restart too.
Timers
timer.after
Calls the function once, after ms milliseconds.
timer.every
Calls the function every ms milliseconds.
timer.cancel
Stops a timer.
Debugging
Own character
player.getPosition
Your character's position (nil until it is in the world).
player.name
Your own nickname.
player.id
Your own number on the server.
player.isInWorld
Is the character in the world (not loading, not in a menu)?
player.getVehicle
The vehicle we sit in and our seat (0 = driving); nil on foot.
player.getVehicleInfo
What a speedometer needs, for the vehicle we sit in (nil on foot): id, seat, speed (km/h), fuel and fuelCapacity (litres), rpm, engineOn, damage and engineDamage (0..100), dirt (0..1).
player.getHealth
Our own health, 0..100.
player.isDead
Whether our character is dead.
Camera
camera.focusPlayer
Smoothly puts the camera in front of the character — e.g. on the face during character creation.
camera.attachToPlayer
The camera sits at from and looks at to; coordinates are in the character's axes (x right, y forward, z up). Follows the character.
camera.lookFrom
The same in world coordinates (for scenes where the character stands still). time as in focusPlayer: 0 = a cut; calling it every half second with 0.6 makes the camera fly smoothly along points.
camera.reset
Brings back the player's normal camera.
camera.worldToScreen
Where a point of the world shows on the screen, in pixels (like ui.screenSize), and how far it is from the camera. nil if it's behind the camera.
camera.screenToWorld
The other way: the point of the world `distance` meters from the camera (1 by default) that shows at pixel sx, sy.
camera.getPosition
Where the camera that renders is (nil if unknown).
camera.getDirection
Where the camera looks: a unit vector (nil if unknown).
Interface (HTML)
web.open
Opens the resource's HTML page over the game (transparent background). One page per resource.
web.focus
Gives the page the mouse and keyboard (a cursor appears, the game gets no input).
web.show
Shows or hides the page without closing it.
web.close
Closes the resource's page.
web.emit
Sends data to the page, where m2o.on(name, fn) receives it.
web.on
Receives data from the page (m2o.emit).
Interface (ImGui)
ui.window
A simple window (Dear ImGui) — for debugging and utility windows. Call it inside ui.onDraw.
ui.onDraw
The function that draws the windows every frame.
ui.setInputEnabled
Gives the ImGui windows the mouse and keyboard.
ui.input
A text field. The label is before ##, a hidden id after ##.
ui.button
A button; true in the frame it is clicked. width = -1 is full width.
Page (JavaScript)
m2o.emit
From the page to the resource's client Lua (web.on). data is any JSON value.
m2o.on
Receives data from Lua (web.emit).
Health
player:getHealth
The player's health, 0..100 (0 = dead).
player:setHealth
Sets the health, 0..100. 0 kills.
player:getMaxHealth
Always 100: health is counted in percent.
player:isDead
Dead and not respawned yet.
player:kill
Kills the player (the character falls and lies there; playerDeath fires).
player:respawn
Brings the player back to life at a place.
player:setInvincible
While on, the player takes no damage (safe zones, admins).
player:setHealthRegen
Whether health comes back by itself (the game's regeneration). nil = the world's setting.
world.setHealthRegen
Health regeneration for everyone (on by default).
playerDamage
A player got hurt.
playerDeath
A player died.
playerRespawn
A player was brought back with respawn.
playerFightStart
A player picked a fist fight with another (pushed their character); the blows come as playerDamage.
Weapons
playerWeaponChange
A player took another weapon in hand (1 = fists; see the weapons page).
playerWeaponFire
A player fired a shot: the weapon, where from (the muzzle) and which way. Everyone who sees them sees the shot; hits are counted by the shooter's game (playerDamage).
player:isAiming
Whether the player aims their weapon (the right mouse button). Everyone who sees them sees the aim.
player:getAimPoint
Where the player aims (what their camera looks at, 50 m ahead), or nil when not aiming.
player:getWeaponInHand
The weapon in the player's hand (1 = fists).
player:giveWeapon
Gives a weapon with ammo (more ammo if they have it already).
player:giveAmmo
Adds ammo for a weapon.
player:removeWeapon
Takes a weapon away.
player:removeAllWeapons
Takes every weapon away.
player:selectWeapon
Puts a weapon in the hands (0 = put away).
player:getWeapons
Weapons the server gave: weapon id -> ammo given (shots fired aren't counted).
weapons
Weapon ids by name.
player:setUnlimitedAmmo
Weapons never run out of ammo.
Client events
weaponChange
We took another weapon in hand (1 = fists).
enterVehicle
We got into a vehicle (seat 0 drives).
exitVehicle
We got out of a vehicle.
playerStreamIn
Another player came near: their character is shown here now.
playerStreamOut
Another player's character isn't shown any more (went away, left).
vehicleStreamIn
One of the server's vehicles came near.
vehicleStreamOut
A vehicle isn't shown any more.
hit
Our blow landed on another player (the server takes the damage off them).
fightStart
A fist fight with another player began: we picked it (weStarted) or they did.
Chat
chat.send
A line in one player's chat.
chat.broadcast
A line in everyone's chat.
player:sendMessage
Same as chat.send(player, ...).
chat.registerCommand
A chat command: /name ... With { permission = "kick" } only players whose group has it may use it.
playerChat
A player said something (not a command).
chat.send (client)
Sends text as if the player typed it (commands too).
Character
player:freeze
Locks the player's controls (true) or gives them back (false).
player:showHud
Shows or hides the game's HUD.
player:fadeScreen
Fades the player's screen to black (true) or back (false).
HUD
player:setHudVisible
One part of the game's HUD for this player: radar, money, speedometer, buttons, messages, info, subtitles, timer, score, respect, lowHealthEffect, all (the whole HUD; wiki: HUD). Stays hidden until shown again.
player:isHudVisible
Whether the server hides that part for the player.
hud.setVisible
Hides / shows a part of the HUD from a client script (on top of what the server hid). Parts: see the wiki's HUD page.
hud.isVisible
Whether this client's scripts hide that part.
Security
security.hashPassword
A password made ready for storing: PBKDF2-SHA256 with a random salt (slow on purpose, so a leaked file can't be cracked quickly). Store the string it gives.
security.verifyPassword
Checks a password against what hashPassword gave.
NPCs
npcs.create
A character of the server's: a shopkeeper, a guard, a passer-by. Everyone near sees the same one; it stands where it's put. Each player is shown the nearest 64 on a budget of their own, and players get character slots first, so NPCs never push out players or traffic.
npcs.getNear
The server's NPCs within radius m, nearest first. Also npcs.all() and npcs.get(id).
npc:walkTo
Walks (or runs) straight to the point; the npcArrived event when there. npc:stop() stands it where it is.
npcs.getNearest
The server's NPC nearest to us within radius m (nil if none). Also npcs.all(), npcs.getName(id), npcs.getPosition(id).
Blips
blips.create
An icon on the map and the radar. Made on the server, every player sees it; made in a client script, only that player does.
blips.attach
An icon that follows a player's character or a vehicle. On the server: a player or a vehicle, everyone sees it. In a client script: a player id (blips.attachVehicle(id, options) for a vehicle), only this player sees it.
Labels
labels.create
A text label in the world. Made on the server, everyone nearby sees it; made in a client script, only that player does.
labels.attach
A label above a player's head that follows them. On the server: a player, everyone sees it. In a client script: a player id, only this player sees it.
Bans
player:ban
Bans the player by name and IP and kicks them. No minutes = forever.
bans.add
Adds a ban (data/bans.json).
bans.remove
Lifts a ban.
bans.list
All bans: { who, reason, until }.
Animations
player:playAnimation
Plays an animation on the player; everyone nearby sees it, including players who come closer later (if looped).
player:stopAnimation
Stops the player's animation.
player:setWalkStyle
How the player walks and stands (drunk, hands in pockets, with an umbrella...); everyone nearby sees it. "" = normal.
player:getWalkStyle
The player's walk style ("" = normal).
player:setItemsInHands
Items in the player's hands (a suitcase, a newspaper, an umbrella...): numbers from the Wiki: items in hands page; -1 or nil = empty hand. Everyone sees it.
player:getItemsInHands
What the server put in the player's hands: left, right (-1 = empty).
Natives
player:callNative
Calls one of the game's own functions (see the Natives page, C_WrapperHuman) on this player's character - in their game and in everyone's who sees them - once.
player:setNative
Like callNative, kept under key: whoever comes near later gets it too, and it's applied again when the character is re-created (new clothes, respawn).
player:clearNative
Forgets a native kept with setNative.
natives.call
Calls one of the game's own script functions (a native): on our character, another player's, one of our vehicles or a game module. The answer comes to callback(ok, results...).
natives.ped
The target for natives.call that is another player's character (while it's shown here).
natives.vehicle
The target for natives.call that is one of the server's vehicles (while it's shown here).
natives.entity
The target for natives.call that is one of the city's own named objects: a shop's door, a gate, a lamp...