getPedOccupiedVehicle | Multi Theft Auto: Wiki Skip to content

getPedOccupiedVehicle

Client-side
Server-side
Shared

Pair: warpPedIntoVehicle

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function gets the vehicle that the ped is currently in or is trying to enter, if any.

OOP Syntax Help! I don't understand this!

  • Note: Set the variable to nil to executeremovePedFromVehicle

  • Method:ped:getOccupiedVehicle(...)
  • Variable: .vehicle

Syntax

vehicle getPedOccupiedVehicle ( ped thePed )
Required Arguments
  • thePed: The ped whose vehicle you're looking up.

Returns

  • vehicle: value

Returns the vehicle that the specified ped is in, or false if the ped is not in a vehicle or is an invalid ped.

Code Examples

shared

When a ped enters the 'getcarname' command and is currently in a vehicle, this example outputs the name of the vehicle.

function showVehicleName ( thePlayer )
local theVehicle = getPedOccupiedVehicle ( thePlayer )
if theVehicle then
outputChatBox ( "Name of the Vehicle: " .. getVehicleName ( theVehicle ), thePlayer )
else
outputChatBox ( "You do not have a Vehicle!", thePlayer, 255, 0, 0, true )
end
end
addCommandHandler ( "getcarname", showVehicleName )

See Also