isPedInVehicle | Multi Theft Auto: Wiki Skip to content

isPedInVehicle

Client-side
Server-side
Shared

Manual Review Required

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


Checks whether or not a given ped is currently in a vehicle.

Note

Client side IsPedInVehicle only returns true if the ped is physically inside a vehicle. To check if the ped is entering or exiting a vehicle, use: getPedOccupiedVehicle (ped) ~= false

Note

Server side IsPedInVehicle returns whether the ped is entering, inside or exiting a vehicle.

OOP Syntax Help! I don't understand this!

  • Method:ped:isInVehicle(...)
  • Variable: .inVehicle

Syntax

bool isPedInVehicle ( ped thePed )
Required Arguments
  • thePed: the ped you want to check.

Returns

  • bool: value

Returns true if the ped is in a vehicle, false if he is on foot or an invalid element was passed.

Code Examples

shared

This code defines anisinvehiclecommand which tells a player whether another player is in a vehicle or not.

-- we create our handler function, where sourcePlayer is the player who sent the command,
-- and checkedPlayerName is the player name specified.
function outputIsInVehicle ( sourcePlayer, commandName, checkedPlayerName )
-- we get the player element from the nick specified
local checkedPlayer = getPlayerFromName ( checkedPlayerName )
-- if there exists a player with that nick
if ( checkedPlayer ) then
-- if he's in a vehicle,
if isPedInVehicle ( checkedPlayer ) then
-- tell the source player
outputChatBox ( checkedPlayerName .. " is in a vehicle.", sourcePlayer )
-- if he's not in a vehicle,
else
-- tell the source player
outputChatBox ( checkedPlayerName .. " is not in a vehicle.", sourcePlayer )
end
-- if it doesn't exist,
else
-- tell the source player
outputChatBox ( "Invalid player name.", sourcePlayer )
end
end
-- define a handler for the isinvehicle command
addCommandHandler ( "isinvehicle", outputIsInVehicle )

See Also