GetObjectRotation: Difference between revisions

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


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


==Example==  
==Example==  
If a player points at an object with a gun, it will output it's rotation to the player.
If a player points at an object with a gun, its rotation will appear in the chat box.
<section name="Server" show="true" class="server">
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPlayerTargeted ( element )
function onPlayerTargeted ( targetElem )
     if ( isElement(element) and getElementType ( element ) == "object") then
     if ( isElement(targetElem) and getElementType(targetElem) == "object" ) then
         local x,y,z = getObjectRotation(element)
         local x,y,z = getObjectRotation ( targetElem )
         outputChatBox("Object rotation: "..x.." "..y.." "..z,source)
         outputChatBox ( "Object rotation: " .. x .. " " .. y .. " " .. z, source )
     end
     end
end
end
Line 29: Line 29:
<section name="Client" class="client">
<section name="Client" class="client">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onPlayerTargeted ( element )
function onPlayerTargeted ( targetElem )
     if ( isElement(element) and getElementType ( element ) == "object") then
     if ( isElement(targetElem) and getElementType (targetElem) == "object" ) then
         local x,y,z = getObjectRotation(element)
         local x,y,z = getObjectRotation ( targetElem )
         outputChatBox("Object rotation: "..x.." "..y.." "..z,source)
         outputChatBox ( "Object rotation: " .. x .. " " .. y .. " " .. z )
     end
     end
end
end

Revision as of 18:14, 19 August 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 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", getRootElement(), onPlayerTargeted )
Click to expand [+]
Client

See Also

Shared