GetPlayerOccupiedVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 12: Line 12:


==Example==
==Example==
This example finds if the player called ''someguy'' is in a vehicle, if they it shows the vehicle's health in the chatbox.
This example outputs the vehicle name of the vehicle if the player is currently occupying one, when he enters the 'vehicleName' command.
<syntaxhighlight lang="lua">if ( vehicle = getPlayerOccupiedVehicle ( findPlayer ( "someguy" ) ) )
<syntaxhighlight lang="lua">
  outputChatBox ( "Someguy is in a vehicle with " .. getVehicleHealth ( vehicle ) .. " health." )
function showVehicleName(player)
else
local vehicle = getPlayerOccupiedVehicle(player)
  outputchatbox ( "Someguy is not in a vehicle." )
if (vehicle ~= false) then
end</syntaxhighlight>
local vehicleName = getVehicleName(vehicle)
outputChatBox("Vehicle name: "..vehicleName,player)
end
end
addCommandHandler("vehicleName",showVehicleName)
</syntaxhighlight>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Revision as of 12:57, 27 July 2007

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

Syntax

vehicle getPlayerOccupiedVehicle ( player thePlayer )

Required Arguments

  • thePlayer: The player whose vehicle you're looking up.

Returns

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

Example

This example outputs the vehicle name of the vehicle if the player is currently occupying one, when he enters the 'vehicleName' command.

function showVehicleName(player)
	local vehicle = getPlayerOccupiedVehicle(player)
	if (vehicle ~= false) then
		local vehicleName = getVehicleName(vehicle)
		outputChatBox("Vehicle name: "..vehicleName,player)
	end
end
addCommandHandler("vehicleName",showVehicleName)

See Also

Shared