Open Road MP

Logging and errors

Write to the server log, how errors and crashes are handled, and several gamemodes on one server.

Logging

mp.log("loaded", 42, { any: "value" })  // info
mp.log.warn("something looks odd")
mp.log.error("something went wrong")

Everything goes to the server window and to server.log, with the gamemode's name in front: [mymode] loaded 42 { any: 'value' }. Values are formatted like console.log does. console.log & co. also end up in the server log.

Errors

  • An error in a handler (event, command, timer) is logged with its stack trace. Other handlers still run, the gamemode keeps going.
  • Wrong arguments to an mp function throw a TypeError or RangeError with a clear message, e.g. players.setLevel: level must be between 0 and 1000, got 5000.
  • A player who left meanwhile: calls for them are ignored, with a warning in the log.

Type check before the start

The server checks every gamemode with TypeScript before it starts it - at server start, on gamemode restart and on the automatic restart after a crash. Wrong names, wrong types or syntax Node.js cannot run (enum ...) stop the start: the errors are in the log with file, line and column, and the gamemode stays off until you fix them and run gamemode restart.

Crashes and restarts

If the gamemode's process ends anyway (for example a syntax error), the server starts it again after 5 seconds. After 3 crashes within a minute it gives up and logs it.

In the server console:

Command
gamemodestate of all gamemodes
gamemode restart mymoderestart one - also to load changed code
gamemode restartrestart all
gamemode stop mymodestop one

A restarted gamemode starts fresh: values kept in variables are gone. Players stay connected, and the gamemode sees them in mp.players.all() right away - there is no new playerJoin for them.

Several gamemodes

gamemodes = [freeroam, mymode] runs both, each in its own process. They:

  • all receive every event,
  • may all call every function,
  • share players and game rules: if one changes a rule, the others see it,
  • share command names: the first gamemode to register a name gets it.

That way you can split a server into parts - for example one gamemode for the economy and one for admin commands.

On this page