GetPedOccupiedVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 15: Line 15:
When a ped enters the 'getcarname' command and is currently in a vehicle, this example outputs the name of the vehicle.
When a ped enters the 'getcarname' command and is currently in a vehicle, this example outputs the name of the vehicle.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function showVehicleName ( player )
function showVehicleName ( thePlayer )
   local theVehicle = getPedOccupiedVehicle ( player )
   local theVehicle = getPedOccupiedVehicle ( thePlayer )
   if theVehicle then
   if theVehicle then
       outputChatBox ( "Name of the Vehicle: " .. getVehicleName ( theVehicle ), player )
       outputChatBox ( "Name of the Vehicle: " .. getVehicleName ( theVehicle ), thePlayer )
   else
   else
       outputChatBox ( "You do not have a Vehicle!", player, 255, 0, 0, true )
       outputChatBox ( "You do not have a Vehicle!", thePlayer, 255, 0, 0, true )
   end
   end
end
end

Revision as of 19:13, 22 January 2011

This function gets the vehicle that the ped is currently in, if any.

Syntax

vehicle getPedOccupiedVehicle ( ped thePed )

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