Skip to content

Gamemodes

A gamemode is your Node.js program: it creates one Server, reacts to events, and changes the world through the objects the server hands it.

The server is in charge

SAGL is server-authoritative where it matters:

  • Weapons and ammo are the server's: a player's game only has what giveWeapon gave it, and every shot is checked for ownership, ammo and fire rate (playerWeaponViolation reports the rest).
  • Hits go through the server: playerDamage and pedDamage can cancel a hit (return false) or change its damage (return 25).
  • Money, stats, wanted levels, vehicle health and colours are what the server says; a player's game changing them by itself is undone.
  • Explosions and vehicle deaths are confirmed by the server (playerExplosion, vehicleDeath).

Events

Handlers run synchronously in the network loop. They may be async, but the events that take a return value (vetoes, replacements) only count what was returned synchronously.

server.on("playerDamage", (victim, attacker, hit) => {
  if (victim.data.team === (attacker as Player).data?.team) return false; // no friendly fire
  if (hit.bodyPart === BodyPart.Head) return hit.damage * 2;
});

All events: Events.

Guides

Project layout

A typical gamemode:

my-gamemode/
  index.ts              # the Server, events
  client/               # clientFiles: downloaded and cached by players
    branding/logo.png
    scripts/hud.js      # client scripts
    ui/shop.rml         # their UI documents
    maps/interior.png   # map overlays
  package.json