GetObjectRotation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(17 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server client function}}
{{Deprecated|getElementRotation|}}
Object rotation can be retrieved from objects in mapfiles or objects that are created in scripts.  
Object rotation can be retrieved from objects in mapfiles or objects that are created in scripts.  


==Syntax==  
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
float float float getObjectRotation ( element object )       
float float float getObjectRotation ( object theObject )       
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''Object:''' The object whose rotation will be retrieved
*'''theObject:''' The object whose rotation will be retrieved


===Returns===
===Returns===
Returns ''true'' if object exists, ''false'' otherwise.
Returns three ''float''s 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 a mapfile object. The object is called "pirateship" in the mapfile. Here is the excerpt from the mapfile:
If a player points at an object with a gun, its rotation will appear in the chat box.
 
<section name="Server" class="server" show="true">
<syntaxhighlight lang="xml">
<syntaxhighlight lang="lua">
<object id="pirateship" posX="-1627.319092" posY="128.543411" posZ="6.581001" rotX="-0.760854" rotY="2.421000" rotZ="0.851000" model="8493"/>
function onPlayerTargeted ( targetElem )
    if ( isElement(targetElem) and getElementType(targetElem) == "object" ) then
        local x,y,z = getObjectRotation ( targetElem )
        outputChatBox ( "Object rotation: " .. x .. " " .. y .. " " .. z, source )
    end
end
addEventHandler ( "onPlayerTarget", root, onPlayerTargeted )
</syntaxhighlight>
</syntaxhighlight>
 
</section>
<section name="Client" class="client">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
root = getRootElement ()
function onPlayerTargeted ( targetElem )
 
    if ( isElement(targetElem) and getElementType (targetElem) == "object" ) then
addEventHandler ( "onMapLoad", root, "onMapLoad" )
        local x,y,z = getObjectRotation ( targetElem )
function onMapLoad ( name, root )
        outputChatBox ( "Object rotation: " .. x .. " " .. y .. " " .. z )
pirateship = getElementByID ( "pirateship" )
    end
if ( pirateship == false ) then
outputChatBox ( "couldn't find the ship!" )
end
rx, ry, rz = getObjectRotation ( pirateship )
outputChatBox ( "Ship RX = "..rx.." SHIP RY = "..ry.." SHIP RZ = "..rz )
end
end
addEventHandler ( "onClientPlayerTarget", root, onPlayerTargeted )
</syntaxhighlight>
</syntaxhighlight>
 
</section>
Result in chatbox:
Ship RX = 316.40628051758 SHIP RY = 2.421000 SHIP RZ = 0.851000


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

Latest revision as of 08:06, 4 November 2020

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Please use getElementRotation instead.


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 floats 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, its rotation will appear in the chat box.

Click to collapse [-]
Server
function onPlayerTargeted ( targetElem )
    if ( isElement(targetElem) and getElementType(targetElem) == "object" ) then
        local x,y,z = getObjectRotation ( targetElem )
        outputChatBox ( "Object rotation: " .. x .. " " .. y .. " " .. z, source )
    end
end
addEventHandler ( "onPlayerTarget", root, onPlayerTargeted )
Click to expand [+]
Client

See Also