GetPlayerOccupiedVehicle: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Removed the client-specific syntax. Client side function also has a player argument.)
Line 4: Line 4:


==Syntax==
==Syntax==
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">vehicle getPlayerOccupiedVehicle ( player thePlayer )</syntaxhighlight>
<syntaxhighlight lang="lua">vehicle getPlayerOccupiedVehicle ( player thePlayer )</syntaxhighlight>


Line 12: Line 11:
===Returns===
===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.
Returns the vehicle that the specified player is in, or ''false'' if the player is not in a vehicle or is an invalid player.
</section>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">vehicle getPlayerOccupiedVehicle ( )</syntaxhighlight>
===Required Arguments===
''None''
===Returns===
Returns the vehicle that the local player is in, or ''false'' if the player is not in a vehicle.
</section>


==Example==
==Example==
When a player enters the 'vehiclename' command and is currently in a vehicle, this example outputs the name of the vehicle.
When a player enters the 'vehiclename' command and is currently in a vehicle, this example outputs the name of the vehicle.
<section name="Server" class="server" show="true">
<section name="Server and client" class="both" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function showVehicleName ( thePlayer )
function showVehicleName ( thePlayer )
Line 33: Line 22:
outputChatBox ( "Vehicle name: " .. vehicleName, thePlayer )
outputChatBox ( "Vehicle name: " .. vehicleName, thePlayer )
end
end
end
addCommandHandler ( "vehiclename", showVehicleName )
</syntaxhighlight>
</section>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
function showVehicleName ( thePlayer )
        local theVehicle = getPlayerOccupiedVehicle ( )
        if ( theVehicle ) then
                local vehicleName = getVehicleName ( theVehicle )
                outputChatBox ( "Vehicle name: " .. vehicleName, thePlayer )
        end
end
end
addCommandHandler ( "vehiclename", showVehicleName )
addCommandHandler ( "vehiclename", showVehicleName )

Revision as of 13:56, 24 November 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 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