Skip to content

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.

server.on("vehicleControlChangeRequest", ({ player, vehicleId, fromState, toState, changedControls }) => boolean | void | Promise<boolean | void>)
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.

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.

Require a driver to be on duty before they turn on headlights.

gamemodes/police.ts
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);
});