Server
const server = new Server(options);
server.on("playerJoin", (player) => { /* ... */ });
server.listen();
Options
new Server(options?: ServerOptions)
| Option |
Type |
Default |
|
port |
number |
7777 |
UDP port. |
name |
string |
|
Shown to players (loading screen, pause menu). |
maxPlayers |
number |
32 |
Player slots. |
startMoney |
number |
0 |
Money each player starts with. |
skinAnimations |
boolean |
false |
Walk and run like their skin rather than CJ (per player: player.skinAnimations). |
weather |
number |
Weather.SunnyLA |
World 0's weather. |
time |
{ hour, minute, frozen? } |
12:00, frozen |
In-game time at startup. |
trustedProxies |
string[] |
|
Proxy mode: only accept players through these IPs, trusting the player IP they forward. |
tickMs |
number |
5 |
How often the network is serviced. |
clientFiles |
string |
|
Directory players download and cache: client files. |
branding |
Branding |
|
Logo, primary and secondary colour: branding. |
Branding
| Field |
Type |
|
logo |
string |
A square PNG or JPEG client file, up to 1 MB. |
background |
string |
A client file (PNG or JPEG) behind the loading screen. |
showName |
boolean |
The loading screen shows the name beside the logo (default: the logo stands in for it). |
primary |
"#RRGGBB" or 0xRRGGBBAA |
Menu items, headings, bars. |
secondary |
"#RRGGBB" or 0xRRGGBBAA |
Behind focused items, under bars. |
Lifecycle
|
|
listen({ console? }) |
Starts accepting players, and the operator console unless { console: false }. Stops cleanly on SIGINT/SIGTERM. |
close() |
Disconnects everyone and stops. |
Server.protocolVersion |
The protocol version clients must speak (static). |
Events
|
|
on(event, listener) |
Adds a listener. See Events. |
off(event, listener) |
Removes it. |
Players
|
|
players |
Connected players. |
player(id) |
A player by id. |
broadcast(text, color?) |
A message to everyone (0xRRGGBB). |
randomSkin() |
A random valid ped model. |
Vehicles
|
|
createVehicle(model, position, heading?, options?) |
A vehicle for everyone, on the ground at position. |
vehicles |
Every vehicle, ambient traffic included. |
vehicle(id) |
A vehicle by id. |
destroyVehicle(vehicle) |
Same as vehicle.destroy(). |
VehicleOptions: colors: [n, n] (0-126), radio (RadioStation),
world, ambient (treated as traffic), respawnDelay (seconds),
plate (up to 8 of A-Z, 0-9, space).
Peds
|
|
createPed(model, position, heading?, options?) |
A ped for everyone. |
peds |
Every ped, the ambient population included. |
ped(id) |
A ped by id. |
destroyPed(ped) |
Same as ped.destroy(). |
PedOptions: world, weapon (Weapon), health (100), behaviour
("stand" or "wander").
Zones, garages, cull zones
|
|
createZone({ center, radius } \| { min, max }, world?) |
A watched area: Zone. |
zones, destroyZone(zone) |
|
garages, garage(id) |
The game's garages: Garage. |
createCullZone({ min, max, world?, audio?, attributes?, mirror? }) |
Interior effects: CullZone. |
destroyCullZone(zone) |
|
Worlds, time and weather
|
|
world(id) |
A virtual world's settings: World. |
setWorldView(viewer, target, visible?) |
viewer world sees target world (one way). |
worldSees(viewer, target) |
Whether it does. |
population |
World 0's ambient population (get/set, partial): Population. |
weather |
World 0's weather (get/set). |
time |
{ hour, minute, frozen } (get), { hour, minute } (set). |
freezeTime(), unfreezeTime() |
|
Client scripts, files, branding, the map
|
|
clientScripts |
ClientScripts: scripts run in every player's game. |
channel(name) |
A Channel to and from client scripts. |
clientFiles |
{ path, size, sha256 }[]: what players download. |
rescanClientFiles() |
Re-reads the directory for players joining from now. Returns the count. |
branding |
Get/set the Branding for players joining from now. Throws (saying why) if the logo isn't a square image client file, or the background isn't a client file. |
map |
Everyone's GameMap. |
console |
The operator Console. |
options |
The options it was created with. |