getElementPosition | Multi Theft Auto: Wiki Skip to content

getElementPosition

Client-side
Server-side
Shared

Pair: setElementPosition

This 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 position of.

Returns

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

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

Code Examples

client

This example will print the player position to chat using /pos command.

function whatsMyPosition()
-- get the position of local player
local fX, fY, fZ = getElementPosition(localPlayer);
-- output it to chat
outputChatBox("My current position is X: "..fX.." Y: "..fY.." Z: "..fZ);
end
addCommandHandler("pos", whatsMyPosition);

See Also

Element Functions