Skip to content

players.putInVehicle

Puts a player straight into a seat of a vehicle, leaving their previous vehicle if they are already seated. It is the gamemode’s own action, so the player’s playerEnterVehicleRequest veto does not apply.

players.putInVehicle(player: PlayerTarget, vehicleId: number, seat?: number): Promise<ActionResult>
Name Type Description
player PlayerTarget The player, or their ID.
vehicleId number The vehicle, as in player.vehicleId or an playerEnteredVehicle event.
seat number Optional. 0 (the default) is the driver’s seat, 1 to 3 passenger seats.

A promise of an ActionResult: applied once the player sits in the seat, rejected with a code, or timeout after five seconds without an answer.

A seat is free when nobody sits in it now: an NPC the vehicle was created with no longer holds the seat once they got out. A player or ped in the seat, or another player on their way into it, keeps it taken.

Put a player back in the last vehicle they drove.

gamemodes/my-mode.ts
import { chat, commands, players, server } from "nativemp";
const lastCar = new Map<number, number>();
server.on("playerExitedVehicle", ({ player, vehicleId, seat }) => {
if (seat === 0) lastCar.set(player.id, vehicleId);
});
commands.register("car", async (player) => {
const vehicleId = lastCar.get(player.id);
if (vehicleId === undefined) return chat.sendServerMessage("You haven't driven anything yet.", player);
const result = await players.putInVehicle(player, vehicleId);
if (result.status === "rejected") chat.sendServerMessage(`Can't get you in (${result.code}).`, player);
});
Code Why
invalid-vehicle No such vehicle, or the seat is not 0 to 3.
occupied-seat Someone, a player or an NPC, is in that seat.
superseded A newer teleport, vehicle placement, exit or spawn replaced this pending transfer.
native-unavailable The game could not complete the exit or entry. The player stays in, or returns to, their previous seat.

Call putInVehicle once: it takes the player out of their current vehicle and the camera follows. You do not need to take them out first or try again. A seat someone sits in rejects without taking the player out of their vehicle. The seat is kept for the player until the move is done or times out.

The previous vehicle stays where it was left. A preceding players.setPosition also leaves the old vehicle behind unless its includeVehicle flag is true.

A captured Player keeps this effect bound to its connection across awaits; see Async handlers.