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

Function

getDistanceBetweenElements

Server and clientElementsTrilogy Hub only

Returns the distance between two elements in metres. With flat = true the height difference is ignored.

Syntax

float getDistanceBetweenElements(element a, element b [, bool flat = false])

Arguments

aelement
The first element.
belement
The second element.
flatbool, optional = false
Horizontal distance only.

Returns

The distance; false for an invalid element, without a warning.

Example

addCommandHandler("dystans", function(player, _, name)
    local other = getPlayerFromName(name or "")
    if other then
        outputChatBox(("%.1f m"):format(getDistanceBetweenElements(player, other)), player)
    end
end)

See also