GetPlayerOccupiedVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
m (Changed "DeprecatedWithAlt" template to "Deprecated")
 
(13 intermediate revisions by 8 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
==Description==
{{Server client function}}
This function returns a [[vehicle]] that the player is currently in, if any. This function returns false if the player is on foot, or the player doesn't exist.
{{Deprecated|getPedOccupiedVehicle|}}
 
This function gets the [[vehicle]] that the player is currently in, if any.


==Syntax==
==Syntax==
[[vehicle]] [[getPlayerOccupiedVehicle]] ( [[player]] player )
<syntaxhighlight lang="lua">vehicle getPlayerOccupiedVehicle ( player thePlayer )</syntaxhighlight>


===Required Arguments===
===Required Arguments===
*'''player''': The [[player]] whose vehcile you're looking up.
*'''thePlayer''': The [[player]] whose vehicle you're looking up.
 
===Returns===
Returns the vehicle that the specified player is in, or ''false'' if the player is not in a vehicle or is an invalid player.


==Example==
==Example==
if ( vehicle = [[getPlayerOccupiedVehicle]] ( [[findPlayer]] ( "Someguy" ) ) )
When a player enters the 'vehiclename' command and is currently in a vehicle, this example outputs the name of the vehicle.
  [[serverchat]] ( "Someguy is in a vehicle with ", [[getVehicleHealth]] ( vehicle ), " health." )
<section name="Server and client" class="both" show="true">
else
<syntaxhighlight lang="lua">
  [[serverchat]] ( "Someguy is not in a vehicle." )
function showVehicleName ( thePlayer )
end
local theVehicle = getPlayerOccupiedVehicle ( thePlayer )
if ( theVehicle ) then
local vehicleName = getVehicleName ( theVehicle )
outputChatBox ( "Vehicle name: " .. vehicleName, thePlayer )
end
end
addCommandHandler ( "vehiclename", showVehicleName )
</syntaxhighlight>
</section>
 
==See Also==
{{Player functions}}

Latest revision as of 16:13, 13 February 2015

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Please use getPedOccupiedVehicle instead.


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 specified player is in, or false if the player is not in a vehicle or is an invalid player.

Example

When a player enters the 'vehiclename' command and is currently in a vehicle, this example outputs the name of the vehicle.

Click to collapse [-]
Server and client
function showVehicleName ( thePlayer )
	local theVehicle = getPlayerOccupiedVehicle ( thePlayer )
	if ( theVehicle ) then
		local vehicleName = getVehicleName ( theVehicle )
		outputChatBox ( "Vehicle name: " .. vehicleName, thePlayer )
	end
end
addCommandHandler ( "vehiclename", showVehicleName )

See Also

Shared