ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. getElementPosition

Function

getElementPosition

Server and clientElementsIdentical to MTA:SA

Returns an element's position in the world: a player, vehicle, object or marker.

Syntax

float, float, float getElementPosition(element el)

Arguments

elelement
The element whose position you want.

Returns

Three numbers x, y, z, or false if the element does not exist.

Example

Distance between two players in metres.

function distance(a, b)
    local x1, y1, z1 = getElementPosition(a)
    local x2, y2, z2 = getElementPosition(b)
    return getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2)
end

addCommandHandler("distance", function(player, _, nick)
    local other = getPlayerFromName(nick or "")
    if not other then return outputChatBox("No such player.", player) end
    outputChatBox(("%s is %.0f m away."):format(nick, distance(player, other)), player)
end)

Notes

Good to know. You set the position with setElementPosition(el, x, y, z). Coordinates are described in Conventions.

See also