GetPedOccupiedVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Server and client now.)
mNo edit summary
Line 13: Line 13:


==Example==
==Example==
When a ped enters the 'vehiclename' 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 ( thePed )
function showVehicleName ( player )
local theVehicle = getPedOccupiedVehicle ( thePed )
  local vehicle = getPedOccupiedVehicle ( player )
if ( theVehicle ) then
      if vehicle then
local vehicleName = getVehicleName ( theVehicle )
        outputChatBox ( "Name of the Vehicle: " .. getVehicleName ( vehicle ), player )
outputChatBox ( "Vehicle name: " .. vehicleName, thePlayer )
      else
end
        outputChatBox ( "You do not have a Vehicle!", player, 255, 0, 0, true )
      end
end
end
addCommandHandler ( "vehiclename", showVehicleName )
addCommandHandler ( "getcarname", showVehicleName )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Client_ped_functions}}
{{Client_ped_functions}}

Revision as of 00:46, 21 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 ( player )
   local vehicle = getPedOccupiedVehicle ( player )
      if vehicle then
         outputChatBox ( "Name of the Vehicle: " .. getVehicleName ( vehicle ), player )
      else
         outputChatBox ( "You do not have a Vehicle!", player, 255, 0, 0, true )
      end
end
addCommandHandler ( "getcarname", showVehicleName )

See Also