Open Road MP

Events

React to players joining and leaving and to everything that happens in their game.

Events are how the server tells your gamemode that something happened. Register a handler with mp.events.on:

mp.events.on("playerJoin", (player) => {
  mp.log(`${player.name} joined`)
})

Several handlers for the same event are fine - they run in the order they were registered. mp.events.off(name, handler) removes one again (pass the same function).

The gamemode

EventWhen
gamemodeStarted()The gamemode is loaded and running: mp.world is filled, players already on the server are in mp.players.all(). Once per start - also after gamemode restart and the automatic restart after a crash. The place for markers, zones and everything that does not wait for a player.
mp.events.on("gamemodeStarted", () => {
  mp.log(`Started with ${mp.players.all().length} players online`)
})

Players

EventWhen
playerJoin(player)A player connected. Their bank balance is 0 and no job is active - set the start money here. The game is still loading.
playerReady(player)The player's game has loaded the world (player.ready). The standard spawn (mp.world.setSpawn) is applied just before your handlers. The place for welcome messages, teleports, vehicles and markers.
playerLeave(player, reason)A player left, timed out or was kicked.
playerChat(player, text)A normal chat message. It has already been sent to everyone.
playerCommand(player, command, args)A chat message starting with /. For your own commands, use mp.commands.add instead - this event is for logging.

The game

These come from the player's game - Open Road MP reads them from ETS2 itself.

EventWhen
playerFined(player, fine)The game fined the player: speed camera, police, red light, crash ... fine.offence says which (list).
jobStarted(player, job)The player took a job - from the game or from your gamemode.
jobLoaded(player, job)The player has the cargo: hooked up the company's trailer at the source, or loaded their own trailer.
jobDelivered(player, job)A freight job was delivered: income, experience, cargo damage, distance ...
jobCancelled(player, job)A job was cancelled, also by mp.players.cancelJob.
tollPaid(player, toll)The player paid a toll.
ferryUsed(player, trip) / trainUsed(player, trip)The player took a ferry or a train, with price and route.
carJobDelivered(player, job) / busJobCompleted(player, job)Car transport and bus jobs of newer game content.
gameEvent(player, name, attributes)Every event of the game in raw form, including the ones above.
mp.events.on("jobDelivered", (player, job) => {
  const damage = (job.cargoDamage * 100).toFixed(1)
  mp.chat.broadcast(`${player.name} delivered for ${job.revenue} € (${job.distanceKm} km, ${damage} % damage)`)
})

mp.events.on("playerFined", (player, fine) => {
  if (fine.offence === "speeding_camera") {
    mp.chat.broadcast(`Flash! ${player.name} was caught speeding.`)
  }
})

Raw game events

gameEvent passes on everything the game reports, with the game's own names - also events that have no typed version (yet):

mp.events.on("gameEvent", (player, name, attributes) => {
  mp.log(`[${name}] ${player.name}`, attributes)
  // e.g. [job.delivered] Anna { "earned.xp": 512, ... }
})

The truck

Open Road MP watches the player's truck (see player.vehicle) and reports these changes:

EventWhen
engineStart(player) / engineStop(player)The engine was started or switched off.
trailerAttach(player) / trailerDetach(player)A trailer was hooked up or unhooked.
playerRefuel(player, liters)The tank got fuller: once per stop at a filling station, when refuelling ends - also after mp.players.setFuel.

A change has to last a second before it is reported, so a short jump (a teleport, a new truck) does not fire anything.

mp.events.on("playerRefuel", (player, liters) => {
  mp.chat.send(player, `${liters.toFixed(0)} l refuelled, ${player.vehicle.fuelRange} km range`)
})

Errors in handlers

If a handler throws, the error and its stack trace go to the server log. The other handlers still run and the gamemode keeps going - see Logging and errors.

All events with their exact parameters: API reference → Events.

On this page