GetElementPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (|)
(4 intermediate revisions by 4 users not shown)
Line 15: 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===
Line 23: Line 24:


==Example==
==Example==
This example spawns a Landstalker and creates a weapon pickup at its position.
<syntaxhighlight lang="lua">
-- create a landstalker, and store its reference in the variable called 'myLandstalker'
myLandstalker = createVehicle ( 400, 1591.596680, -2495.323242, 18.098244 )
-- create a weapon pickup at the vehicle's position
createPickup ( getElementPosition ( myLandstalker ), 2, 31 )
</syntaxhighlight>
This example attaches a samsite on the player's vehicle.
This example attaches a samsite on the player's vehicle.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 46: Line 38:
==See Also==
==See Also==
{{Element functions}}
{{Element functions}}
[[de:GetElementPosition]]

Revision as of 03:36, 1 January 2015

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;
myElegy = createVehicle ( 562, 1591.596680, -2495.323242, 18.098244 ) 
-- get the vehicle's position;
local x,y,z = getElementPosition( myElegy )
-- create the samsite;
samsite = createObject ( 3267, x, y, z + 3 )
-- attach the samsite to the elegy;
attachElementToElement ( samsite, myElegy, 0, 0, 0 )

See Also