SetPlayerRotation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{Server function}}
{{Server function}}
{{Needs_Checking|The rotation must be a varible, it cannot be an actual number. For example, getplayerrotation and set it to a varible, then set player rotation to that varible + 10. Vehicle rotation function worked with a number. Other rotation functions may not be accepting numbers too, but vehicle did. So I doubt it. -Ransom}}
[[Category:Incomplete]]


__NOTOC__  
__NOTOC__  
This function allows you to set the current rotation of the specified player.
This example allows a player to type the command 'disco', which will result in the player being rotated to a random direction every 1 second, infinite times.


==Syntax==  
==Syntax==  
Line 20: Line 18:
==Example==  
==Example==  
This example code makes the player named Cheesepie look south.
This example code makes the player named Cheesepie look south.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">function discoTime ( player, command )
cheesepie = getPlayerFromNick ( "Cheesepie" )    -- try to get the player by his nick
-- Randomly choose a new playe rotation and set it
if ( cheesepie ) then                            -- make sure we found him (there may be no player named Cheesepie on the server)
newRotation = math.random ( 0, 360 )
    setPlayerRotation ( cheesepie, 180 )         -- set his roation
     setPlayerRotation ( player, newRotation )
end
 
--When 'disco' command is typed
function initiateDiscoMode ( player, commandName )
--Trigger a random change in player rotation every second.
--Send the player who activated discoTime to the function so his rotation will be changed.
setTimer (discoTime, 1000, 0, player )
end
end
</syntaxhighlight>
addCommandHandler ( "disco", initiateDiscoMode )</syntaxhighlight>


==See Also==
==See Also==

Revision as of 08:04, 11 October 2007


This example allows a player to type the command 'disco', which will result in the player being rotated to a random direction every 1 second, infinite times.

Syntax

bool setPlayerRotation ( player thePlayer, float rotation )         

Required Arguments

  • thePlayer: The player to set the rotation of
  • rotation: A float specifying the desired rotation.

Returns

Returns true if successful, false otherwise.

Example

This example code makes the player named Cheesepie look south.

function discoTime ( player, command )
	-- Randomly choose a new playe rotation and set it
	newRotation = math.random ( 0, 360 )
    setPlayerRotation ( player, newRotation )
end

--When 'disco' command is typed
function initiateDiscoMode ( player, commandName )
--Trigger a random change in player rotation every second.
--Send the player who activated discoTime to the function so his rotation will be changed.
setTimer (discoTime, 1000, 0, player )
end
addCommandHandler ( "disco", initiateDiscoMode )

See Also