Skip to content

GameMap

import { GameMap } from "@sagl/server";

The pause menu's map. server.map is everyone's (players joining later get it too); player.map is one player's. Client scripts have their own, apart: sagl.map.

Ids are 1-32 characters. Colours are 0xRRGGBBAA or "#RRGGBB[AA]".


setMarker(id, options)

setMarker(id: string, options: MapMarkerOptions): this

Adds a marker, or moves the one with that id.

Parameter Type Description
id string Its id.
options.x, options.y number Where, in world coordinates.
options.icon number The game's radar sprite, 1-63. 0 or left out: a diamond in color.
options.color MapColor For the diamond.
options.label string Shown beside it (up to 48 characters).

Throws RangeError for a bad id.

server.map.setMarker("bank", { x: 1462, y: -1012, icon: 52, label: "Bank" });
player.map.setMarker("target", { x: 2000, y: -1500, color: "#ff3030", label: "Target" });

removeMarker(id)

removeMarker(id: string): this
server.map.removeMarker("bank");

setOverlay(id, options)

setOverlay(id: string, options: MapOverlayOptions): this

Puts an image over a world rectangle (custom terrain, a floor plan), or replaces the one with that id.

Parameter Type Description
id string Its id.
options.x1, y1, x2, y2 number Two opposite corners, in world coordinates.
options.file string A client file, PNG or JPEG (cached by players).
options.image Buffer | string Or the image's bytes, or a path on the server (sent each time).
options.opacity number 0-1, default 1.
options.layer number Higher draws on top. Default 0.

Throws Error if file isn't a client file; TypeError with neither file nor image.

server.map.setOverlay("airport", {
  x1: 1400, y1: -2700, x2: 2200, y2: -2200,
  file: "maps/airport.png", opacity: 0.8,
});

removeOverlay(id)

removeOverlay(id: string): this

setWorld(visible, background?)

setWorld(visible: boolean, background?: MapColor): this

Shows or hides the game's own map under the markers and overlays.

Parameter Type Description
visible boolean false hides it.
background MapColor What shows instead. Default black.
// Inside an interior: only its floor plan, GTA V style.
player.map.setWorld(false, "#000000");
player.map.setOverlay("floor", { x1: -20, y1: -20, x2: 20, y2: 20, file: "maps/club.png" });