vehicles.getById
Reads one vehicle the server knows: one your gamemode created, one of the game’s parked cars, or traffic, in any virtual
world. The snapshot stays current as the vehicle is created, entered, damaged, moved, respawned and removed.
vehicles.isValid tells you whether the server knows the vehicle at all.
Signature
Section titled “Signature”vehicles.getById(id: number): VehicleSnapshot | undefinedvehicles.isValid(id: number): booleanParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
id |
number |
The vehicle’s network ID. |
Returns
Section titled “Returns”getById returns an immutable VehicleSnapshot, or undefined for an ID the server
does not know or a vehicle that was removed. isValid returns true while the server knows the vehicle.
Example
Section titled “Example”import { server, vehicles } from "nativemp";
server.on("playerEnteredVehicle", ({ player, vehicleId }) => { const vehicle = vehicles.getById(vehicleId); if (!vehicle) return; const speed = Math.hypot(...vehicle.velocity) * 3.6; server.log(`${player.name} got into a ${vehicle.model} going ${speed.toFixed(0)} km/h`);});Related
Section titled “Related”vehicles.listAll: every vehiclevehicles.getDistanceFromPoint: distance to a pointvehicleSnapshotsUpdated: when snapshots changeVehicleSnapshot: the fields