vehicles.setState
Sets explicit target values on any active networked vehicle. Repeating the same values is safe and emits no change event.
Parts the model does not support are ignored, and the promise resolves as applied without an event.
With its engine off, a vehicle does not move under its own power: a car, bike or boat gets no throttle, a helicopter’s
rotor slows, and a plane loses thrust. An empty vehicle keeps the engine setting you gave it. Getting in as the driver
turns the engine on and asks vehicleControlChangeRequest.
Signature
Section titled “Signature”vehicles.setState(id: number, update: VehicleStateUpdate): Promise<ActionResult>vehicles.setEngineOn(id: number, isEngineOn: boolean): Promise<ActionResult>vehicles.setHeadlights(id: number, headlights: VehicleHeadlightMode): Promise<ActionResult>vehicles.setWindowOpen(id: number, window: VehicleWindowName, isOpen: boolean): Promise<ActionResult>vehicles.setDoorOpen(id: number, door: VehicleDoorName, isOpen: boolean): Promise<ActionResult>vehicles.setHoodOpen(id: number, isOpen: boolean): Promise<ActionResult>vehicles.setTrunkOpen(id: number, isOpen: boolean): Promise<ActionResult>vehicles.setLocked(id: number, isLocked: boolean): Promise<ActionResult>vehicles.setCondition(id: number, condition: Partial<VehicleCondition>): Promise<ActionResult>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
id |
number |
The vehicle’s network ID. |
update |
VehicleStateUpdate |
The explicit values to set. Fields left out keep their current values. |
isEngineOn |
boolean |
Whether the engine is on. |
headlights |
VehicleHeadlightMode |
auto, on or off. on shows them with the engine off too; on auto they show only while the engine runs. Helicopters, boats and many planes have none. On auto every player sees the same lights. |
window |
VehicleWindowName |
Which supported window to set. |
door |
VehicleDoorName |
Which supported door to set. |
isOpen |
boolean |
The target position for a window, door, hood or trunk. |
isLocked |
boolean |
Whether it is locked. A locked vehicle of any kind keeps every player out, without asking playerEnterVehicleRequest. |
condition |
Partial<VehicleCondition> |
Health or damage-manager condition to set. |
Returns
Section titled “Returns”A promise of an ActionResult: applied, rejected for an invalid update or unknown
vehicle, or timeout if the server does not answer within five seconds. Unsupported parts are a quiet applied
no-op. A real control change emits vehicleControlChanged; a health or damage
change emits vehicleDamaged. An isSirenOn change emits the existing
vehicleSirenChanged event and uses the existing
vehicleSirenChangeRequest for player input.
setCondition accepts health from 0 to 1000, damage-manager status fields, four wheel values from 0 to 4, and supported
door/hood/trunk damage states. Setting a part’s open state preserves its existing damage. Use the full
VehicleCondition shape for details.
Example
Section titled “Example”import { server, vehicles } from "nativemp";
server.on("playerEnteredVehicle", async ({ vehicleId }) => { await vehicles.setState(vehicleId, { isEngineOn: true, headlights: "auto" });});Related
Section titled “Related”vehicles.getState: read shared statevehicles.restoreState: apply a saved snapshot after spawningvehicles.repair: clear damage and restore healthvehicleControlChangeRequest: decide player input