GetDistanceBetweenCoords
Docslocal retval = GetDistanceBetweenCoords(x1, y1, z1, x2, y2, z2, useZ)Description
Returns the distance between two three-dimensional points, optionally ignoring the Z values.
If useZ is false, only the 2D plane (X-Y) will be considered for calculating the distance.
Consider using this faster native instead: SYSTEM::VDIST - DVIST always takes in consideration the 3D coordinates.
Parameters
| Name | Type | Description |
|---|---|---|
x1 | float | The X coordinate of the first point. |
y1 | float | The Y coordinate of the first point. |
z1 | float | The Z coordinate of the first point. |
x2 | float | The X coordinate of the second point. |
y2 | float | The Y coordinate of the second point. |
z2 | float | The Z coordinate of the second point. |
useZ | BOOL | Whether or not to use the Z coordinate. |
Quick Snippet: Get Coordinatesx1y1z1x2
x1y1z1x2Add this command to your client script to retrieve precise locations in-game.
-- Add this to your client.lua. Type /pos in-game to copy coords.
RegisterCommand('pos', function()
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local heading = GetEntityHeading(ped)
local output = string.format("vector4(%.2f, %.2f, %.2f, %.2f)", coords.x, coords.y, coords.z, heading)
print(output)
TriggerEvent('chat:addMessage', { args = { '^4[COORD]^0', output } })
end)Returns
floatReturns a floating-point number.
Examples
Official
local dist = GetDistanceBetweenCoords(0.0, 0.0, 0.0, 5.0, 5.0, 5.0, true)
-- language faster equivalent:
local firstVec = vector3(0.0, 0.0, 0.0)
local secondVec = vector3(5.0, 5.0, 5.0)
local dist = #(firstVec - secondVec) -- Use Z
local dist = #(firstVec.xy - secondVec.xy) -- Do not use Z