GetElementPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(Improve example.)
 
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Server client function}}
__NOTOC__
__NOTOC__
An Element is anything which has been defined or can be retrieved from Lua.  The getElementPosition function allows you to retrieve the location of any element.
The getElementPosition function allows you to retrieve the position coordinates of an element.  This can be any real world element, including:
* [[Element/Player|Players]]
* [[Element/Vehicle|Vehicles]]
* [[Element/Object|Objects]]
* [[Element/Pickup|Pickups]]
* [[Element/Marker|Markers]]
* [[Element/Collision shape|Collision shapes]]
* [[Element/Blip|Blips]]
* [[Element/Radar area|Radar areas]]


==Syntax==
==Syntax==
Line 6: Line 15:
float, float, float getElementPosition ( element theElement )
float, float, float getElementPosition ( element theElement )
</syntaxhighlight>
</syntaxhighlight>
{{OOP||[[element]]:getPosition|position|setElementPosition}}


===Required Arguments===
===Required Arguments===
*'''theElement:''' The element in which you'd like to retrieve the location of
*'''theElement:''' The element which you'd like to retrieve the location of


===Returns===
===Returns===
Returns three floats indicating the position of the element, ''x'', ''y'' and ''z'' respectively.
Returns three ''float''s indicating the position of the element, ''x'', ''y'' and ''z'' respectively.


==Example==
==Example==
Explain what the example does here
This example attaches a samsite on the player's vehicle.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- create a landstalker, and store it's reference in the variable called 'myLandstalker'
-- Create the elegy
myLandstalker = createVehicle ( 400, 1591.596680, -2495.323242, 18.098244 )  
local myElegy = createVehicle(562, 1591.596680, -2495.323242, 18.098244)  
-- Create a weapon pickup at the vehicle's position
-- Get the vehicle's position
createPickup ( getElementPosition ( myLandstalker ), 2, 31 )
local x, y, z = getElementPosition(myElegy)
-- Create the samsite
local samsite = createObject(3267, x, y, z + 3)
-- Attach the samsite to the elegy
attachElementToElement(samsite, myElegy, 0, 0, 0)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Element functions}}
{{Element functions}}
[[de:GetElementPosition]]

Latest revision as of 15:52, 1 October 2021

The getElementPosition function allows you to retrieve the position coordinates of an element. This can be any real world element, including:

Syntax

float, float, float getElementPosition ( element theElement )

OOP Syntax Help! I don't understand this!

Method: element:getPosition(...)
Variable: .position
Counterpart: setElementPosition


Required Arguments

  • theElement: The element which you'd like to retrieve the location of

Returns

Returns three floats indicating the position of the element, x, y and z respectively.

Example

This example attaches a samsite on the player's vehicle.

-- Create the elegy
local myElegy = createVehicle(562, 1591.596680, -2495.323242, 18.098244) 
-- Get the vehicle's position
local x, y, z = getElementPosition(myElegy)
-- Create the samsite
local samsite = createObject(3267, x, y, z + 3)
-- Attach the samsite to the elegy
attachElementToElement(samsite, myElegy, 0, 0, 0)

See Also