SetObjectRotation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__
Allows you to change an objects rotation while playing a map. The object can be from the map file or created in a script.
{{Server client function}}
Allows you to change an object's rotation while playing a map. The object can be from the map file or created in a script.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setObjectRotation ( element object, float rotX, float rotY, float rotZ )         
bool setObjectRotation ( object theObject, float rotX, float rotY, float rotZ )         
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''Object:''' The object to be rotated
*'''theObject:''' The object to be rotated
*'''rotX:''' Rotation X value
*'''rotX:''' Rotation around the X axis
*'''rotY:''' Rotation Y value
*'''rotY:''' Rotation around the Y axis
*'''rotZ:''' Rotation Z value
*'''rotZ:''' Rotation around the Z axis


===Returns===
===Returns===
Line 21: Line 22:
<object id="pirateship" posX="-1627.319092" posY="128.543411" posZ="6.581001" rotX="-0.760854" rotY="2.421000" rotZ="0.851000" model="8493"/>
<object id="pirateship" posX="-1627.319092" posY="128.543411" posZ="6.581001" rotX="-0.760854" rotY="2.421000" rotZ="0.851000" model="8493"/>
</syntaxhighlight>
</syntaxhighlight>


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onResourceStart ( name, root )
function onResourceStart ( name, root )
rotX = 0
    -- predefined variables, needed for the math code below
rotY = 0
    rotX = 0
rotZ = 0 -- predefined varibles, needed for the math code below
    rotY = 0
pirateship = getElementByID ( "pirateship" ) -- assign element named 'pirateship' in map file to variable
    rotZ = 0
    -- assign element named 'pirateship' in map file to variable
    pirateship = getElementByID ( "pirateship" )
end
end


function chatboxShipRotateLeft ( playerSource, commandName ) -- On console command 'increaserotations'
function chatboxShipRotateLeft ( playerSource, commandName ) -- On console command 'increaserotations'
outputChatBox ( "Rotational values increased" )
    outputChatBox ( "Rotational values increased" )
rotX = rotX + 10
    -- rotations = rotations + 10
rotY = rotY + 10
    rotX = rotX + 10
rotZ = rotZ + 10 -- rotations = rotations + 10
    rotY = rotY + 10
setObjectRotation ( pirateship, rotX, rotY, rotZ ) -- Changed rotation is applied
    rotZ = rotZ + 10
    -- Changed rotation is applied
    setObjectRotation ( pirateship, rotX, rotY, rotZ )
end     
end     


function chatboxShipRotateRight ( playerSource, commandName ) -- On console command 'decreaserotations'
function chatboxShipRotateRight ( playerSource, commandName ) -- On console command 'decreaserotations'
outputChatBox ( "Rotational values decreased" )
    outputChatBox ( "Rotational values decreased" )
rotX = rotX - 10
    -- rotations = rotations - 10
rotY = rotY - 10
    rotX = rotX - 10
rotZ = rotZ - 10 -- rotations = rotations - 10
    rotY = rotY - 10
setObjectRotation ( pirateship, rotX, rotY, rotZ ) -- Changed rotation is applied
    rotZ = rotZ - 10
    -- Changed rotation is applied
    setObjectRotation ( pirateship, rotX, rotY, rotZ )
end
end


-- Set up event and command handlers
addEventHandler ( "onResourceStart", getRootElement(), onResourceStart )
addEventHandler ( "onResourceStart", getRootElement(), onResourceStart )



Revision as of 10:16, 16 August 2007

Allows you to change an object's rotation while playing a map. The object can be from the map file or created in a script.

Syntax

bool setObjectRotation ( object theObject, float rotX, float rotY, float rotZ )        

Required Arguments

  • theObject: The object to be rotated
  • rotX: Rotation around the X axis
  • rotY: Rotation around the Y axis
  • rotZ: Rotation around the Z axis

Returns

Returns true if successful, false otherwise.

Example

In this example, I refer to an object in the map file with the ID "pirateship":

<object id="pirateship" posX="-1627.319092" posY="128.543411" posZ="6.581001" rotX="-0.760854" rotY="2.421000" rotZ="0.851000" model="8493"/>


function onResourceStart ( name, root )
    -- predefined variables, needed for the math code below
    rotX = 0
    rotY = 0
    rotZ = 0
    -- assign element named 'pirateship' in map file to variable
    pirateship = getElementByID ( "pirateship" )
end

function chatboxShipRotateLeft ( playerSource, commandName ) -- On console command 'increaserotations'
    outputChatBox ( "Rotational values increased" )
    -- rotations = rotations + 10
    rotX = rotX + 10
    rotY = rotY + 10
    rotZ = rotZ + 10
    -- Changed rotation is applied
    setObjectRotation ( pirateship, rotX, rotY, rotZ )
end     

function chatboxShipRotateRight ( playerSource, commandName ) -- On console command 'decreaserotations'
    outputChatBox ( "Rotational values decreased" )
    -- rotations = rotations - 10
    rotX = rotX - 10
    rotY = rotY - 10
    rotZ = rotZ - 10
    -- Changed rotation is applied
    setObjectRotation ( pirateship, rotX, rotY, rotZ )
end

-- Set up event and command handlers
addEventHandler ( "onResourceStart", getRootElement(), onResourceStart )

addCommandHandler ( "increaserotations", chatboxShipRotateLeft )
addCommandHandler ( "decreaserotations", chatboxShipRotateRight )

See Also