GetElementRotation: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (→Syntax) |
||
(14 intermediate revisions by 11 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{Server client function}} | ||
__NOTOC__ | __NOTOC__ | ||
Retrieve the rotation of elements. | Retrieve the rotation of elements. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
float float float getElementRotation ( element theElement ) | float, float, float getElementRotation ( element theElement [, string rotOrder = "default" ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP||[[element]]:getRotation|rotation|setElementRotation}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theElement:''' The element whose rotation will be retrieved | *'''theElement:''' The element whose rotation will be retrieved | ||
===Optional Arguments=== | |||
*'''rotOrder:''' A string representing the rotation order desired when returning the [http://en.wikipedia.org/wiki/Euler_angles euler angles]. If omitted, default value is ''"default"''. Allowed values are: | |||
**''"default":'' default MTA behavior prior to 1.1, where rotation order depends on element type | |||
**''"ZXY":'' rotation about the Z axis (''up''), then about the resulting X axis (''right'') and finally about the resulting Y axis (''front''). This is the default rotation order for [[object|objects]] | |||
**''"ZYX":'' rotation about the Z axis (''up''), then about the resulting Y axis (''front''), and finally about the resulting X axis (''right''). This is the default rotation order for [[vehicle|vehicles]] | |||
The default rotation order for peds/players is Z-Y-X (clientside) and -Z-Y-X (serverside) but those rotation orders (set using ''"default"'' on peds) can not be used manually on other element types since they only exist due to historical and backward compatibility reasons. | |||
Specifying a rotation order other than ''"default"'' allows the same angles to later be uniformly used on several elements without having to consider their type. | |||
===Returns=== | ===Returns=== | ||
* ''rx, ry, rz'': 3 ''float''s representing the Euler rotation angles on the axis X, Y and Z (with the rotation order depending on the ''rotOrder'' argument) if ''element'' exists and is a valid element, ''false'' if it's invalid. | |||
==Example== | ==Example== | ||
If a player points at a player element with a gun, its rotation will appear in the chat box. | If a player points at a player element with a gun, its rotation will appear in the chat box. | ||
<section name=" | <section name="Client" class="client" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function onPlayerTargeted ( targetElem ) | function onPlayerTargeted ( targetElem ) | ||
Line 35: | Line 34: | ||
end | end | ||
end | end | ||
addEventHandler ( "onClientPlayerTarget", | addEventHandler ( "onClientPlayerTarget", root, onPlayerTargeted ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> | ||
==See Also== | ==See Also== | ||
{{ | {{Client_element_functions}} |
Latest revision as of 14:24, 29 August 2018
Retrieve the rotation of elements.
Syntax
float, float, float getElementRotation ( element theElement [, string rotOrder = "default" ] )
OOP Syntax Help! I don't understand this!
- Method: element:getRotation(...)
- Variable: .rotation
- Counterpart: setElementRotation
Required Arguments
- theElement: The element whose rotation will be retrieved
Optional Arguments
- rotOrder: A string representing the rotation order desired when returning the euler angles. If omitted, default value is "default". Allowed values are:
- "default": default MTA behavior prior to 1.1, where rotation order depends on element type
- "ZXY": rotation about the Z axis (up), then about the resulting X axis (right) and finally about the resulting Y axis (front). This is the default rotation order for objects
- "ZYX": rotation about the Z axis (up), then about the resulting Y axis (front), and finally about the resulting X axis (right). This is the default rotation order for vehicles
The default rotation order for peds/players is Z-Y-X (clientside) and -Z-Y-X (serverside) but those rotation orders (set using "default" on peds) can not be used manually on other element types since they only exist due to historical and backward compatibility reasons. Specifying a rotation order other than "default" allows the same angles to later be uniformly used on several elements without having to consider their type.
Returns
- rx, ry, rz: 3 floats representing the Euler rotation angles on the axis X, Y and Z (with the rotation order depending on the rotOrder argument) if element exists and is a valid element, false if it's invalid.
Example
If a player points at a player element with a gun, its rotation will appear in the chat box.
Click to collapse [-]
Clientfunction onPlayerTargeted ( targetElem ) if ( isElement(targetElem) and getElementType (targetElem) == "player" ) then local x,y,z = getElementRotation ( targetElem ) outputChatBox ( "Target player rotation: " .. x .. " " .. y .. " " .. z ) end end addEventHandler ( "onClientPlayerTarget", root, onPlayerTargeted )
See Also
- getElementBoneMatrix
- getElementBonePosition
- getElementBoneRotation
- getElementBoundingBox
- getElementDistanceFromCentreOfMassToBaseOfModel
- getElementLighting
- getElementRadius
- isElementCollidableWith
- isElementLocal
- isElementOnScreen
- isElementStreamable
- isElementStreamedIn
- isElementSyncer
- isElementWaitingForGroundToLoad
- setElementBoneMatrix
- setElementBonePosition
- setElementBoneRotation
- setElementCollidableWith
- setElementStreamable
- updateElementRpHAnim
- Shared
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement