From Multi Theft Auto: Wiki
Revision as of 17:56, 15 May 2020 by Lettify (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Checks whether or not a given ped is currently in a vehicle. This also returns true if they're trying to enter a vehicle.

[[{{{image}}}|link=]] Note: Client side IsPedInVehicle can be unreliable. Solution is to use: getPedOccupiedVehicle(ped) ~= false


bool isPedInVehicle ( ped thePed )

OOP Syntax Help! I don't understand this!

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

Required Arguments

  • thePed: the ped you want to check.


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


This code defines an isinvehicle command 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,
			-- tell the source player
			outputChatBox ( checkedPlayerName .. " is not in a vehicle.", sourcePlayer )
	-- if it doesn't exist,
		-- tell the source player
		outputChatBox ( "Invalid player name.", sourcePlayer )

-- define a handler for the isinvehicle command
addCommandHandler ( "isinvehicle", outputIsInVehicle )

See Also