GetElementPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (|)
(Improve example.)
 
Line 26: Line 26:
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">
-- create the elegy;
-- Create the elegy
myElegy = createVehicle ( 562, 1591.596680, -2495.323242, 18.098244 )  
local myElegy = createVehicle(562, 1591.596680, -2495.323242, 18.098244)  
-- get the vehicle's position;
-- Get the vehicle's position
local x,y,z = getElementPosition( myElegy )
local x, y, z = getElementPosition(myElegy)
-- create the samsite;
-- Create the samsite
samsite = createObject ( 3267, x, y, z + 3 )
local samsite = createObject(3267, x, y, z + 3)
-- attach the samsite to the elegy;
-- Attach the samsite to the elegy
attachElementToElement ( samsite, myElegy, 0, 0, 0 )
attachElementToElement(samsite, myElegy, 0, 0, 0)
</syntaxhighlight>
</syntaxhighlight>



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