Skip to content
M2O Scripting APIScripting reference
GuideMaintainer authored

Overview

M2O resources run JavaScript in one of two environments:

  • Server resources run in Node.js and own authoritative game state — players, vehicles, world, money.
  • Client resources run in a sandboxed V8 context on each player’s machine and control local presentation and input — HUD, key binds, web views, the camera.

Use the navigation to browse the globals available to the selected environment. The same declarations that generate this reference can be loaded by an editor for autocomplete and type checking.

Events.on("playerConnect", (player) => {
// HUD text is local to the owning client: send an intent and let the client draw it.
player.emit("mygm:welcome", JSON.stringify({ text: `Welcome, ${player.nickname}`, seconds: 5 }));
const spawn = new Vector3(250, 120, 0);
const vehicle = Vehicle.spawn(32, spawn);
vehicle.setColor(140, 20, 20);
});
Events.on("mygm:welcome", (data) => {
Hud.showMessage(data.text, data.seconds);
});
Key.bind("f6", () => {
Hud.setVisible(!Hud.isVisible());
});
const player = LocalPlayer;
if (player) {
const screen = Camera.worldToScreen(player.position.x, player.position.y, player.position.z);
console.log(screen.x, screen.y, screen.visible);
}

Start here:

The two ideas everything builds on:

  • Events — listeners, the client↔server bridge, and the trust boundary.
  • Server, client, and the UI — why UI is client-side and the intent pattern that follows.

Server-side systems: chat and commands, the player lifecycle, vehicles, streamed content (custom and replacement cars), world entities and triggers, shops and economy, persistence, and seasons.

Client-side systems: the HUD and native UI, input and controls, Render2D, and web views.

Illustrated catalogs: weapon IDs, map blip icons, vehicle wheel models, weather templates, marker models, prop models, character models, hand props, and animation clips.