GetPlayerOccupiedVehicle

From Multi Theft Auto: Wiki
Revision as of 14:44, 19 August 2007 by Arc (talk | contribs)
Jump to navigation Jump to search

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

Syntax

Click to collapse [-]
Server
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.

Click to collapse [-]
Client
vehicle getPlayerOccupiedVehicle ( )

Required Arguments

None

Returns

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

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
function showVehicleName ( thePlayer )
	local theVehicle = getPlayerOccupiedVehicle ( thePlayer )
	if ( theVehicle ) then
		local vehicleName = getVehicleName ( theVehicle )
		outputChatBox ( "Vehicle name: " .. vehicleName, thePlayer )
	end
end
addCommandHandler ( "vehiclename", showVehicleName )
Click to collapse [-]
Client
function showVehicleName ( thePlayer )
        local theVehicle = getPlayerOccupiedVehicle ( )
        if ( theVehicle ) then
                local vehicleName = getVehicleName ( theVehicle )
                outputChatBox ( "Vehicle name: " .. vehicleName, thePlayer )
        end
end
addCommandHandler ( "vehiclename", showVehicleName )

See Also