Open Road MP

Overview

What a gamemode is, what it can do and how it runs.

A gamemode decides what happens on a server. The server itself only connects the players - everything else is up to the gamemode:

  • how much money players start with and what they earn
  • chat commands like /repair, /tp or /time
  • reactions to what happens in the game: speed cameras, deliveries, tolls, ferries ...
  • game rules for everyone: police, traffic, fatigue, fuel ...
  • jobs, vehicles, licence plates, teleports, time of day

Gamemodes are written in TypeScript (or plain JavaScript) and run in Node.js - no build step, no compiler.

gamemodes/mymode/index.ts
mp.events.on("playerJoin", (player) => {
  mp.players.setMoney(player, 5000)
  mp.chat.send(player, `Welcome, ${player.name}!`)
})

mp.events.on("playerFined", (player, fine) => {
  mp.chat.broadcast(`${player.name}: ${fine.label} (${fine.amount} €)`)
})

mp.commands.add("repair", "repairs your truck", (player) => {
  mp.players.repair(player)
})

How it runs

  • Every gamemode is a folder in gamemodes/ with an index.ts. The server starts each gamemode listed in server.cfg in its own Node.js process.
  • The whole API is the global object mp - no import needed. Its types come with the server, so your editor completes and checks everything.
  • The server sends events (a player joined, a job was delivered ...) to the gamemode, the gamemode calls functions (mp.players.setMoney(...)) that the server carries out in the player's game.
  • An error in your code is logged and does not take the server down. A crashed gamemode is restarted automatically.

Where to go next

On this page