GetPlayerRotation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{deprecated}}
{{Needs_Checking|Why is this deprecated? [[User:Erorr404|Erorr404]]}}
{{Needs_Checking|I believe it is getElementRotation or something.. [[User:Talidan2|Talidan]]}}
{{Needs_Checking|There is no getElementRotation, since rotation is different for different elements. [[User:Erorr404|Erorr404]]}}
__NOTOC__
__NOTOC__
==Description==
This function returns the current rotation (in degrees) of a player around the Z axis. It's used with on-foot players: use [[getVehicleRotation]] on the occupied [[vehicle]] if the player is in one.
This function returns a float containing the current rotation (in degrees) of the player. Its values lie between 0 and 359. This function can fail if the player is in a car. Use the [[getVehicleRotation]] function in this case. If this function does fail, the first argument will be set to 'false'.


==Syntax==
==Syntax==
float [[getPlayerRotation]] ( [[player]] player )
<syntaxhighlight lang="lua">
float getPlayerRotation ( player thePlayer )
</syntaxhighlight>


===Required Arguments===
===Required Arguments===
*'''player''': The [[player]] whose rotation you want to retrieve.
*'''thePlayer''': the [[player]] whose rotation you want to retrieve.
 
===Returns===
Returns a ''float'' containing the player's rotation, or ''false'' if an invalid player (or one in a vehicle) was passed.


==Example==
==Example==
fRot = [[getPlayerRotation]] ( [[findPlayer]] ( "someguy" ) )
This code adds a ''getrot'' command to get the player's current rotation.
if ( fRot )
<syntaxhighlight lang="lua">
  [[serverChat]] ( "Someguy's current rotation: ", fRot, "." )
-- register outputPlayerRotation as a handler for the getrot command
end
addCommandHandler ( "getrot", "outputPlayerRotation" )
 
function outputPlayerRotation ( sourcePlayer )
-- if the command was triggered by an ingame player
if ( sourcePlayer ) then
-- if he is in a vehicle
if isPlayerInVehicle ( sourcePlayer ) then
-- store the vehicle element
local playerVehicle = getPlayerOccupiedVehicle ( sourcePlayer )
-- and output its rotation
outputChatBox ( "Your vehicle's rotation is: " .. getVehicleRotation ( playerVehicle ), sourcePlayer )
-- if he is on foot
else
-- output the player's rotation
outputChatBox ( "Your rotation is: " .. getPlayerRotation ( sourcePlayer ), sourcePlayer )
end
end
end
</syntaxhighlight>


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

Revision as of 18:45, 22 April 2007

This function returns the current rotation (in degrees) of a player around the Z axis. It's used with on-foot players: use getVehicleRotation on the occupied vehicle if the player is in one.

Syntax

float getPlayerRotation ( player thePlayer )

Required Arguments

  • thePlayer: the player whose rotation you want to retrieve.

Returns

Returns a float containing the player's rotation, or false if an invalid player (or one in a vehicle) was passed.

Example

This code adds a getrot command to get the player's current rotation.

-- register outputPlayerRotation as a handler for the getrot command
addCommandHandler ( "getrot", "outputPlayerRotation" )

function outputPlayerRotation ( sourcePlayer )
	-- if the command was triggered by an ingame player
	if ( sourcePlayer ) then
		-- if he is in a vehicle
		if isPlayerInVehicle ( sourcePlayer ) then
			-- store the vehicle element
			local playerVehicle = getPlayerOccupiedVehicle ( sourcePlayer )
			-- and output its rotation
			outputChatBox ( "Your vehicle's rotation is: " .. getVehicleRotation ( playerVehicle ), sourcePlayer )
		-- if he is on foot
		else
			-- output the player's rotation
			outputChatBox ( "Your rotation is: " .. getPlayerRotation ( sourcePlayer ), sourcePlayer )
		end
	end
end

See Also