getElementPosition | Multi Theft Auto: Wiki Skip to content

getElementPosition

Client-side
Server-side
Shared

Pair: setElementPosition

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


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

OOP Syntax Help! I don't understand this!

  • Method:element:getPosition(...)
  • Variable: .position

Syntax

float,​ float,​ float getElementPosition ( element theElement )
Required Arguments
  • theElement: The element which you'd like to retrieve the location of

Returns

  • float: x
  • float: y
  • float: z

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

Code Examples

shared

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

Element Functions