GetObjectRotation: Difference between revisions

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


===Returns===
===Returns===
Returns ''true'' if object exists, ''false'' otherwise.
Returns three ''float'' if object exists, ''false'' in the first variable and ''nil'' in the other two if it's invalid.


==Example==  
==Example==  
In this example, I refer to an object in the mapfile with the ID "pirateship":
If a player points at an object with a gun, it will output it's rotation to the player.
<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"/>
</syntaxhighlight>
The following code gets the object element by ID and outputs it's rotation:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onMapLoad", root, "mapStart" )
function onPlayerTargeted ( element )
function mapStart ( name ) -- this function gets called when the map starts
    if ( isElement(element) and getElementType ( element ) == "object") then
  pirateship = getElementByID ( "Pirate Ship" ) -- get the object element
local x,y,z = getObjectRotation(element)
  if ( pirateship ) then
        outputChatBox("Object rotation: "..x.." "..y.." "..z,source)
      rx, ry, rz = getObjectRotation ( pirateship ) -- get the rotation of the object
    end
      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 object, 'Pirate Ship!'" )
  end
end
end
addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTargeted )
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 23:03, 28 July 2007

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 three float if object exists, false in the first variable and nil in the other two if it's invalid.

Example

If a player points at an object with a gun, it will output it's rotation to the player.

function onPlayerTargeted ( element )
    if ( isElement(element) and getElementType ( element ) == "object") then
		local x,y,z = getObjectRotation(element)
        outputChatBox("Object rotation: "..x.." "..y.." "..z,source)
    end
end
addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTargeted )

See Also