GetElementPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
__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.


==Syntax==
==Syntax==
Line 8: Line 8:


===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==
This example spawns a Landstalker and creates a weapon pickup at it's position.
This example spawns a Landstalker and creates a weapon pickup at its position.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- create a landstalker, and store it's reference in the variable called 'myLandstalker'
-- create a landstalker, and store its reference in the variable called 'myLandstalker'
myLandstalker = createVehicle ( 400, 1591.596680, -2495.323242, 18.098244 )  
myLandstalker = createVehicle ( 400, 1591.596680, -2495.323242, 18.098244 )  
-- Create a weapon pickup at the vehicle's position
-- create a weapon pickup at the vehicle's position
createPickup ( getElementPosition ( myLandstalker ), 2, 31 )
createPickup ( getElementPosition ( myLandstalker ), 2, 31 )
</syntaxhighlight>
</syntaxhighlight>




This example attaches a samsite on the players vehicle.
This example attaches a samsite on the player's vehicle.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- create the elegy;
-- create the elegy;
vehicle = getPlayerOccupiedVehicle ( 562, 1591.596680, -2495.323242, 18.098244 )  
myElegy = createVehicle ( 562, 1591.596680, -2495.323242, 18.098244 )  
-- get the vehicles position;
-- get the vehicle's position;
local x,y,z = getElementPosition(vehicle)
local x,y,z = getElementPosition( myElegy )
-- Create the samsite;
-- create the samsite;
samsite = createObject ( 3267, x, y, z + 3 )
samsite = createObject ( 3267, x, y, z + 3 )
-- attach the samsite to the elegy;
-- attach the samsite to the elegy;
attachElementToElement ( samsite, vehicle, 0, 0, 0 )
attachElementToElement ( samsite, myElegy, 0, 0, 0 )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Element functions}}
{{Element functions}}

Revision as of 18:51, 19 August 2007

The getElementPosition function allows you to retrieve the position coordinates of an element.

Syntax

float, float, float getElementPosition ( element theElement )

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 spawns a Landstalker and creates a weapon pickup at its position.

-- 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 )


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