Vehicles and peds¶
Vehicles¶
const car = server.createVehicle(411, { x: 2493, y: -1660, z: 13.3 }, 90, {
colors: [1, 0], // carcols.dat palette, 0-126
plate: "SAGL 01",
radio: RadioStation.RadioLosSantos,
respawnDelay: 60, // back where it was, a minute after it's wrecked or abandoned
world: 0,
});
Whoever drives a vehicle simulates it and syncs it to everyone; empty, it stays where it was left. The server keeps its health, damage, colours, plate and radio:
car.health = 1000;
car.repair();
car.colors = [3, 3];
car.plate = "NEW PLT";
car.damage = { ...car.damage, tyres: [TyreDamage.Burst, 0, 0, 0] };
car.explode(player); // credited to player
car.respawn();
car.destroy();
Events: playerEnterVehicle, playerExitVehicle, vehicleDeath (return
false to save it), vehicleRespawn, vehicleRadio.
server.on("vehicleDeath", (vehicle, killer) => {
if (vehicle.data.indestructible) return false; // repaired instead
});
Peds¶
Server peds are NPCs everyone sees the same. The nearest player's game runs each one's AI as in single-player: it flees, fights back, falls, dies.
const guard = server.createPed(280, { x: 1550, y: -1675, z: 16.2 }, 90, {
weapon: Weapon.Pistol,
health: 150,
behaviour: "stand", // or "wander"
});
const taxi = server.createVehicle(420, { x: 1540, y: -1680, z: 13.5 });
const driver = server.createPed(7, taxi.position);
driver.putInVehicle(taxi, 0); // a "wander" driver drives the roads
Peds' hits on players and other peds go through the server too:
playerDamage and pedDamage get a Player or a Ped as attacker.
pedViolation reports when the game simulating a ped claimed something
impossible; after a few, another player's game takes it over.