SetObjectRotation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setObjectRotation ( element object, float rx, float ry, float rz )         
bool setObjectRotation ( element object, float rotX, float rotY, float rotZ )         
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''Object:''' The object to be rotated
*'''Object:''' The object to be rotated
*'''rx:''' Rotation X value
*'''rotX:''' Rotation X value
*'''ry:''' Rotation Y value
*'''rotY:''' Rotation Y value
*'''rz:''' Rotation Z value
*'''rotZ:''' Rotation Z value


===Returns===
===Returns===
Line 17: Line 17:


==Example==  
==Example==  
In this example, I refer to an object in the mapfile with the ID "pirateship":
In this example, I refer to an object in the map file with the ID "pirateship":
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<object id="Pirate Ship" posX="-1627.319092" posY="128.543411" posZ="6.581001" rotX="-0.760854" rotY="2.421000" rotZ="0.851000" model="8493"/>
<object id="pirateshi[" 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">
addEventHandler ( "onMapLoad", root, "onMapLoad" )
 
function onMapLoad ( name, root )  
function onResourceStart ( name, root )
rx = 0
rotX = 0
ry = 0
rotY = 0
rz = 0 -- predefined varibles, for math code below
rotZ = 0 -- predefined varibles, needed for the math code below
pirateship = getElementByID ( "pirateship" ) --assign element named 'pirateship' in map file to varible            
pirateship = getElementByID ( "pirateship" ) -- assign element named 'pirateship' in map file to varible            
end
end


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


addCommandHandler ( "decreaserotations", "chatboxShipRotateRight" ) --Repeat and subtracted values to decrease rotations
 
function chatboxShipRotateRight ( playerSource, commandName )
function chatboxShipRotateRight ( playerSource, commandName ) -- On console command 'decreaserotations'
outputChatBox ( "Rotational values decreased" )  
outputChatBox ( "Rotational values decreased" )
rx = rx - 10
rotX = rotX - 10
ry = ry - 10
rotY = rotY - 10
rz = rz - 10  
rotZ = rotZ - 10 -- rotations = rotations - 10
setObjectRotation ( pirateship, rx, ry, rz )
setObjectRotation ( pirateship, rotX, rotY, rotZ ) -- Changed rotation is applied
end
end
addEventHandler ( "onResourceStart", getRootElement(), onResourceStart )
addCommandHandler ( "increaserotations", chatboxShipRotateLeft )
addCommandHandler ( "decreaserotations", chatboxShipRotateRight )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Object functions}}
{{Object functions}}

Revision as of 05:04, 5 August 2007

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

Syntax

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

Required Arguments

  • Object: The object to be rotated
  • rotX: Rotation X value
  • rotY: Rotation Y value
  • rotZ: Rotation Z value

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="pirateshi[" posX="-1627.319092" posY="128.543411" posZ="6.581001" rotX="-0.760854" rotY="2.421000" rotZ="0.851000" model="8493"/>

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


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


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

addEventHandler ( "onResourceStart", getRootElement(), onResourceStart )

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

See Also

Shared