GetPedOccupiedVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(fix oop syntax)
Line 5: Line 5:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">vehicle getPedOccupiedVehicle ( ped thePed )</syntaxhighlight>
<syntaxhighlight lang="lua">vehicle getPedOccupiedVehicle ( ped thePed )</syntaxhighlight>
{{OOP|This function is also a static function underneath the Ped class.|[[Ped]]:getOccupiedVehicle|vehicle|}}
{{OOP||[[ped]]:getOccupiedVehicle|vehicle|}}


===Required Arguments===
===Required Arguments===

Revision as of 16:10, 1 January 2015

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

Syntax

vehicle getPedOccupiedVehicle ( ped thePed )

OOP Syntax Help! I don't understand this!

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


Required Arguments

  • thePed: The ped whose vehicle you're looking up.

Returns

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

Example

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