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
giveWeapongave it, and every shot is checked for ownership, ammo and fire rate (playerWeaponViolationreports the rest). - Hits go through the server:
playerDamageandpedDamagecan 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¶
- Players: joining, spawning, money, weapons, stats, messages.
- Vehicles and peds: creating, driving, damage, NPCs.
- Worlds, zones and population: virtual worlds, time and weather, ambient life, police, zones, garages.
- Client files and branding: what players download, and your server's logo and colours.
Project layout¶
A typical gamemode: