Skip to content

Zone and Garage

import { Zone, Garage, GarageType } from "@sagl/server";

Zone

From server.createZone(): an area players are watched against. Fires zoneEnter, zoneLeave and zoneMove.

Properties

Name Type Description
id number
garage Garage | null The garage it covers, for garage zones.
data Record<string, unknown> Your own state.
exists boolean False once destroyed.

destroy()

destroy(): void

Stops watching it. No zoneLeave events are sent.

const pickup = server.createZone({ center: { x: 2500, y: -1660, z: 13.5 }, radius: 1.5 });
pickup.data.reward = 500;
server.on("zoneEnter", (player, zone) => {
  if (zone !== pickup) return;
  player.giveMoney(zone.data.reward as number);
  zone.destroy();
});

Garage

From server.garages: the game's garages. Players' games run none of their logic. The server runs the Pay 'n' Sprays and mod shops; build anything else from zoneEnter on garage.zone.

Properties

Name Type Description
id number
name string From the map files; not unique.
type number GarageType: PayNSpray, SafehouseGanton, ImpoundLS, ...
position Vector3
zone Zone Over its floor.
isOpen boolean The door.
center Vector3 The middle of its floor.

contains(position, margin?)

contains(position: Vector3, margin?: number): boolean

Whether a spot is inside the garage, at least margin m from its walls. A car's position with a margin of about half its length (2.6 m) is a car wholly inside: as the game's garages check before shutting their door. A negative margin reaches that far outside.

outside(position, distance?)

outside(position: Vector3, distance?: number): { position: Vector3; heading: number }

The spot distance m (default 4) outside the wall nearest position, across from it, facing away from the garage. Given where a car drove in, that's in front of the door: where to put a car driving out.

open(), close()

open(): void
close(): void

Opens or closes its door, for everyone.

const sprays = server.garages.filter((g) => g.type === GarageType.PayNSpray);
sprays.forEach((g) => g.open());