Vdist
Docslocal retval = Vdist(x1, y1, z1, x2, y2, z2)Description
Introduced in build 323
Calculates the distance between two points in 3D space. For performance reasons, consider using direct mathematical calculations for distance, as they can be more efficient than calling this native function.
Parameters
| Name | Type | Description |
|---|---|---|
x1 | float | X coordinate of the first point. |
y1 | float | Y coordinate of the first point. |
z1 | float | Z coordinate of the first point. Represents the height or elevation at the first point. |
x2 | float | X coordinate of the second point. |
y2 | float | Y coordinate of the second point. |
z2 | float | Z coordinate of the second point. Represents the height or elevation at the second point. |
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
-- Define a set of coordinates
local coords = vector3(145.0, 200.0, 1000.0)
-- Get the player's current ped
local playerPed = PlayerPedId()
-- Get the player's current coordinates
local coordsPlayer = GetEntityCoords(playerPed, false)
-- Calculate the distance between the player and the coordinates
local distance = Vdist(coordsPlayer.x, coordsPlayer.y, coordsPlayer.z, coords.x, coords.y, coords.z)
if (distance < 10.0) then
print("You are close to the coordinates")
else
print("You are far from the coordinates")
end