vehicleControlChangeRequest
Asks your gamemode before the server accepts a player’s in-game change to a vehicle control. The payload includes the
previous state, the requested state, and the names of controls that changed. Script setters do not ask this decision.
Getting in as the driver turns the engine on and asks. An engine that stops by itself (the vehicle sinks, its rider
falls off into water, it is wrecked) does not ask: it arrives as
vehicleControlChanged with changeSource "game". The same goes for an
open door, hood or trunk that swings shut by itself, for example as the vehicle drives off: it stays shut and is
never asked, so you cannot keep it open by returning false. To hold a part open, set it again with
vehicles.setState.
The siren keeps its separate vehicleSirenChangeRequest.
Signature
Section titled “Signature”server.on("vehicleControlChangeRequest", ({ player, vehicleId, fromState, toState, changedControls }) => boolean | void | Promise<boolean | void>)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
player |
PlayerSnapshot |
The player whose game reported the input. |
vehicleId |
number |
The vehicle’s network ID. |
fromState |
VehicleStateSnapshot |
The currently accepted state. |
toState |
VehicleStateSnapshot |
The state requested by the player’s game. |
changedControls |
readonly VehicleControlName[] |
Changed controls, such as isEngineOn, windows.frontLeft, or isHoodOpen. |
Returns
Section titled “Returns”Return false to keep the previous controls. Any other answer allows the change. A denied change is corrected in the
player’s game and is not published to other players. See how decisions work.
Example
Section titled “Example”Require a driver to be on duty before they turn on headlights.
import { server } from "nativemp";
const onDuty = new Set<number>();server.on("vehicleControlChangeRequest", ({ player, changedControls, toState }) => { if (changedControls.includes("headlights") && toState.headlights !== "off") return onDuty.has(player.id);});Related
Section titled “Related”- How decisions work: deadline and handler rules
vehicleControlChanged: a control change was acceptedVehicleControlChangeRequestPayload: decision payload