Worlds, zones and population¶
Virtual worlds¶
Every player, vehicle and ped is in a virtual world (0 by default). Players see and meet only their own world, plus worlds it views:
player.world = 10; // a safehouse
server.setWorldView(10, 0); // world 10 sees the street (one way)
vehicle.world = 10; // moves its occupants too
Time and weather¶
server.time = { hour: 21, minute: 30 };
server.freezeTime();
server.weather = Weather.RainySF;
const desert = server.world(3);
desert.weather = Weather.SandstormDesert; // world 3 gets its own
desert.synced = true; // ...and follows world 0 again
Ambient population¶
Off by default. Each world uses world 0's settings unless given its own.
server.population = {
peds: true,
traffic: true,
density: 1, // 0-3, 1 is single-player's
gangs: true, // in their territories
police: true, // patrols, and cops responding to wanted players
ambulance: true,
fire: true,
wanted: true, // crimes make players wanted, as in single-player
};
populationSpawn sees each ped or car a player's game proposes and can
refuse it (return false).
Zones¶
const shop = server.createZone({ center: { x: 1368, y: -1279, z: 13.5 }, radius: 3 });
const yard = server.createZone({ min: { x: 2400, y: -1700, z: 0 }, max: { x: 2500, y: -1600, z: 40 } });
server.on("zoneEnter", (player, zone) => {
if (zone === shop) player.emit("shop", { open: true });
});
server.on("zoneLeave", (player, zone) => { /* ... */ });
Garages¶
server.garages are the game's garages: a door you open and close for
everyone, and a zone over the floor. Players' games run none of their logic,
so a Pay 'n' Spray is yours to build:
for (const g of server.garages.filter((g) => g.type === GarageType.PayNSpray)) {
g.open();
server.on("zoneEnter", (player, zone) => {
if (zone !== g.zone || !player.vehicle || player.seat !== 0) return;
player.vehicle.repair();
player.vehicle.colors = [Math.floor(Math.random() * 127), 1];
player.giveMoney(-100);
});
}
Cull zones¶
Areas with the game's interior effects: music, no rain, camera close-in, a mirror.
server.createCullZone({
min: { x: 285, y: -41, z: 1000 }, max: { x: 300, y: -30, z: 1005 },
audio: AudioZone.AmmuNation,
attributes: ZoneAttribute.NoRain | ZoneAttribute.CameraCloseIn,
});
Full reference: World, Zone and Garage.