- Documentation
- Shared functions
- getPedOccupiedVehicle
Function
getPedOccupiedVehicle
Returns the vehicle a ped is sitting in (as the driver or a passenger). When the ped is on foot it returns false. It is the simplest way to find out what a player is driving, e.g. to repair or recolour their car.
Syntax
vehicle getPedOccupiedVehicle(ped ped)Arguments
pedped- A player or an NPC.
Returns
The vehicle, or false when the ped is on foot.
Example
addCommandHandler("napraw", function(player)
local car = getPedOccupiedVehicle(player)
if car then fixVehicle(car) end
end)
See also
getPedOccupiedVehicleSeatReturns the seat number a ped occupies: 0 is the driver, 1 the front passenger, 2 and 3 the rear seats (buses and trains also use higher numbers). When the ped is on foot it returnsfalse. Useful when a command should work only for the driver.isPedInVehicleChecks whether a ped is sitting in any vehicle (in any seat). It also returnsfalsewhile the ped is still getting in, before it takes the seat. When you need the vehicle itself, usegetPedOccupiedVehicle.warpPedIntoVehicleInstantly puts a player or an NPC into the chosen vehicle seat, without walking up and without the get-in animation. If the ped was in another car, it is taken out of it first. When the chosen seat is occupied by someone else, nothing happens and the function returnsfalse. The player's game receives the order immediately, and the server blocks the player from getting out on their own for 3 seconds so the warp is not undone. An NPC in a vehicle always stays seated: while it is in the car, its body has no collision (only bullets hit it), walking and turning wait until it leaves the car, and if the game takes it out of the seat, the client puts it back at once.