- Documentation
- Shared functions
- getVehicleOccupant
Function
getVehicleOccupant
Returns the player or ped sitting in the given seat of a vehicle. Seat 0 is the driver, 1 the front passenger, 2 and 3 the rear seats.
Syntax
player getVehicleOccupant(vehicle vehicle [, int seat = 0])Arguments
vehiclevehicle- The vehicle.
seatint, optional = 0- Seat number.
Returns
The player or ped in the seat, or false when it is empty.
Example
addCommandHandler("kierowca", function(player)
local vehicle = getPedOccupiedVehicle(player)
local driver = vehicle and getVehicleOccupant(vehicle, 0)
if driver and getElementType(driver) == "player" then
outputChatBox("Kierowca: " .. getPlayerName(driver), player)
end
end)
See also
getVehicleOccupantsReturns everyone (players and peds) sitting in the vehicle as a table of seat number → occupant. Empty seats are not in the table, so loop over it withpairs, notipairs(seat 0 is not an array index).getVehicleControllerReturns the vehicle's driver (the occupant of seat 0), orfalsewhen nobody is driving.getPedOccupiedVehicleReturns the vehicle a ped is sitting in (as the driver or a passenger). When the ped is on foot it returnsfalse. It is the simplest way to find out what a player is driving, e.g. to repair or recolour their car.