SetElementRotation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Undo revision 22769 by Awwu (Talk))
No edit summary
Line 23: Line 23:
local localPlayer = getLocalPlayer()
local localPlayer = getLocalPlayer()
function carRotate( )
function carRotate( )
     if isPlayerInVehicle(localPlayer) then -- if the local client is in a vehicle
     if isPedInVehicle(localPlayer) then -- if the local client is in a vehicle
         localVehicle = getPlayerOccupiedVehicle(localPlayer)
         localVehicle = getPedOccupiedVehicle(localPlayer)
         if getVehicleController(localVehicle) == localPlayer then -- if the local client is the controller (driver) of the vehicle
         if getVehicleController(localVehicle) == localPlayer then -- if the local client is the controller (driver) of the vehicle
             local rotX, rotY, rotZ = getElementRotation(localVehicle) -- get the local client's vehicle rotation
             local rotX, rotY, rotZ = getElementRotation(localVehicle) -- get the local client's vehicle rotation

Revision as of 14:20, 1 April 2010

Sets the rotation of elements according to the world (does not work with players that are on the ground).

Syntax

bool setElementRotation ( element theElement, float rotX, float rotY, float rotZ )       

Required Arguments

  • theElement: The element whose rotation will be set
  • rotX: The element's rotation around the x axis in degrees
  • rotY: The element's rotation around the y axis in degrees
  • rotZ: The element's rotation around the z axis in degrees

Returns

Returns true if the element rotation was successfully set and false otherwise.

Example

When a player used the command "turn" and they are the driver of a vehicle the vehicle will rotate 10 degrees clockwise

Click to collapse [-]
Client
local localPlayer = getLocalPlayer()
function carRotate( )
    if isPedInVehicle(localPlayer) then -- if the local client is in a vehicle
        localVehicle = getPedOccupiedVehicle(localPlayer)
        if getVehicleController(localVehicle) == localPlayer then -- if the local client is the controller (driver) of the vehicle
            local rotX, rotY, rotZ = getElementRotation(localVehicle) -- get the local client's vehicle rotation
            setElementRotation(localVehicle,rotX,rotY,rotZ+10) -- turn the vehicle 10 degrees clockwise
         end
    end
end
addCommandHandler ( "turn", carRotate )

See Also