Introduction
A gamemode is the script that makes a Native MP server yours. It greets players, decides who may join and where they spawn, adds chat commands, and moves, arms, freezes or kicks players. The traffic, pedestrians and police are the game’s own and stay in sync without a line of script.
Gamemodes are written in TypeScript and run in Node.js beside the server. The server ships with one,
freeroam.ts: global chat plus /help and /players.
The SDK
Section titled “The SDK”A gamemode imports what it needs from nativemp:
import { areas, bans, camera, chat, checkpoints, commands, damage, fires, interactions, mapIcons, objects, pickups, players, screen, server, textLabels, vehicles, world } from "nativemp";| Import | What it’s for |
|---|---|
server |
Events and decisions, console logging, server options |
players |
Reading players and acting on them: spawn, position, virtual world, health, weapons, vehicles, money, wanted level, color, spectating, kick, ban |
vehicles |
Vehicles of your own, and every vehicle’s siren, horn and radar marker |
objects |
Static objects of your own: ramps, walls, signs, things players can use |
interactions |
Players using vending machines, food carts, gym machines and your objects |
fires |
The fires burning now, and putting them out |
chat |
Reading chat lines and sending colored messages to everyone, one player or the players nearby |
commands |
Registering /commands, optionally for authorised players only |
world |
The clock, weather, world rules and radar markers every player shares |
damage |
What players’ hits on each other do: friendly fire, team and player damage, off |
pickups |
Pickups of your own that every player sees |
textLabels |
3D text in the world |
mapIcons |
Icons on the radar and map |
checkpoints |
Checkpoints players walk or drive into, apart from the race checkpoint |
areas |
Boxes and spheres the server watches, with an optional color on the radar |
screen |
Big on-screen messages |
camera |
A player’s camera: fixed at a place, or following a player, vehicle or object |
bans |
Listing and removing address bans |
Events and decisions
Section titled “Events and decisions”The server tells your gamemode what happens through server.on.
- An event tells you something already happened:
playerConnected,playerDied,playerEnteredVehicleand the rest. What your handler returns is ignored. - A decision asks you first, and waits for your answer before the action goes ahead:
playerConnectRequest(may this player join?),playerEnterVehicleRequest(may they get in?) and many more. Every decision name ends inRequest. Each has a deadline, and a default for when you do not answer in time.
How decisions work explains decisions once, with a table of every decision, its answers, its deadline and its default. The glossary explains the words the docs use.
Write your first gamemode, then see how a gamemode’s folder fits together. When a handler awaits a database, read async handlers. Upgrading a gamemode from before 0.28? The renamed names list every old name and its new one.