vehicles.getState
Reads the current shared state of any active networked vehicle, including ambient vehicles. Parts the model does not support are omitted. Use the small getters when you need one value.
Signature
Section titled “Signature”vehicles.getState(id: number): VehicleStateSnapshot | undefinedvehicles.isEngineOn(id: number): boolean | undefinedvehicles.getHeadlights(id: number): VehicleHeadlightMode | undefinedvehicles.isWindowOpen(id: number, window: VehicleWindowName): boolean | undefinedvehicles.isDoorOpen(id: number, door: VehicleDoorName): boolean | undefinedvehicles.isHoodOpen(id: number): boolean | undefinedvehicles.isTrunkOpen(id: number): boolean | undefinedvehicles.isLocked(id: number): boolean | undefinedvehicles.getCondition(id: number): VehicleCondition | undefinedThe former getEngineOn, getWindowOpen, getDoorOpen, getHoodOpen, getTrunkOpen and getLocked getters still
work for this minor version and warn once. Use the is… getters above.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
id |
number |
The vehicle’s network ID. |
window |
VehicleWindowName |
The window to read. |
door |
VehicleDoorName |
The door to read. |
Returns
Section titled “Returns”getState returns an immutable VehicleStateSnapshot, or undefined when the
vehicle has no current shared state. The individual getters return their value, or undefined when the vehicle is
unknown or that part is unsupported. getCondition returns health and the condition supported by that model.
Example
Section titled “Example”import { server, vehicles } from "nativemp";
server.on("playerEnteredVehicle", ({ vehicleId }) => { const state = vehicles.getState(vehicleId); if (state) server.log(`Engine ${state.isEngineOn ? "on" : "off"}; headlights ${state.headlights}`);});Related
Section titled “Related”vehicles.setState: change controls or conditionVehicleStateSnapshot: fields in the snapshotVehicleCondition: damage and health fields