GetObjectRotation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 14: Line 14:


==Example==  
==Example==  
In this example, I refer to an object in the mapfile. The object is called "pirateship". Here is the excerpt from the mapfile:
In this example, I refer to an object in the mapfile with the ID "pirateship":
 
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<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="Pirate Ship" posX="-1627.319092" posY="128.543411" posZ="6.581001" rotX="-0.760854" rotY="2.421000" rotZ="0.851000" model="8493"/>
</syntaxhighlight>
</syntaxhighlight>
 
The following code gets the object element by ID and outputs it's rotation:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
root = getRootElement ()
root = getRootElement ()


addEventHandler ( "onMapLoad", root, "onMapLoad" )
addEventHandler ( "onMapLoad", root, "mapStart" )
function onMapLoad ( name, root )
function mapStart ( name ) -- this function gets called when the map starts
pirateship = getElementByID ( "pirateship" )
  pirateship = getElementByID ( "Pirate Ship" ) -- get the object element
if ( pirateship == false ) then
  if ( pirateship ) then
outputChatBox ( "couldn't find the ship!" )
      rx, ry, rz = getObjectRotation ( pirateship ) -- get the rotation of the object
end
      outputChatBox ( "Ship RX = "..rx.." SHIP RY = "..ry.." SHIP RZ = "..rz )
rx, ry, rz = getObjectRotation ( pirateship )
      -- output: Ship RX = 316.40628051758 SHIP RY = 2.421000 SHIP RZ = 0.851000
outputChatBox ( "Ship RX = "..rx.." SHIP RY = "..ry.." SHIP RZ = "..rz )
  else
      outputChatBox ( "Couldn't find the ship!" )
  end
end
end
</syntaxhighlight>
</syntaxhighlight>
Result in chatbox:
Ship RX = 316.40628051758 SHIP RY = 2.421000 SHIP RZ = 0.851000


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

Revision as of 03:21, 9 September 2006

Object rotation can be retrieved from objects in mapfiles or objects that are created in scripts.

Syntax

float float float getObjectRotation ( object theObject )       

Required Arguments

  • theObject: The object whose rotation will be retrieved

Returns

Returns true if object exists, false otherwise.

Example

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

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

The following code gets the object element by ID and outputs it's rotation:

root = getRootElement ()

addEventHandler ( "onMapLoad", root, "mapStart" )
function mapStart ( name ) -- this function gets called when the map starts
   pirateship = getElementByID ( "Pirate Ship" ) -- get the object element
   if ( pirateship ) then
      rx, ry, rz = getObjectRotation ( pirateship ) -- get the rotation of the object
      outputChatBox ( "Ship RX = "..rx.." SHIP RY = "..ry.." SHIP RZ = "..rz )
      -- output: Ship RX = 316.40628051758 SHIP RY = 2.421000 SHIP RZ = 0.851000
   else
      outputChatBox ( "Couldn't find the ship!" )
   end
end

See Also