Skip to content

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.

vehicles.getById(id: number): VehicleSnapshot | undefined
vehicles.isValid(id: number): boolean
Name Type Description
id number The vehicle’s network ID.

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.

gamemodes/my-mode.ts
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`);
});