MiscClient

getDistanceBetweenCoords

GET_DISTANCE_BETWEEN_COORDS0xF1B760881820C952

The GTA V native GET_DISTANCE_BETWEEN_COORDS of the MISC namespace, as LS:MP client scripts call it: the global function getDistanceBetweenCoords, in JavaScript and in Lua.

SignatureJavaScript
getDistanceBetweenCoords(
  x1: number,
  y1: number,
  z1: number,
  x2: number,
  y2: number,
  z2: number,
  useZ: boolean
): number
SignatureLua
getDistanceBetweenCoords(
  x1: number,
  y1: number,
  z1: number,
  x2: number,
  y2: number,
  z2: number,
  useZ: boolean
): number

Usage

JavaScript
const value = getDistanceBetweenCoords(x1, y1, z1, x2, y2, z2, useZ);
Lua
local value = getDistanceBetweenCoords(x1, y1, z1, x2, y2, z2, useZ)

Three consecutive numbers can be given as one vector: { x, y, z } (or [x, y, z]) in JavaScript, a Vector3 in Lua.

JavaScript · with vectors
const value = getDistanceBetweenCoords(pos1, pos2, useZ);
Lua · with vectors
local value = getDistanceBetweenCoords(pos1, pos2, useZ)

Parameters

ParameterTypeJavaScriptLua
x1floatnumbernumber
y1floatnumbernumber
z1floatnumbernumber
x2floatnumbernumber
y2floatnumbernumber
z2floatnumbernumber
useZBOOLbooleanboolean

Returns

float JavaScript number, Lua number

Notes

From the community native database. Names are LS:MP’s; samples may be written for C++ or another framework.

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: vdist - DVIST always takes in consideration the 3D coordinates.

Reference

Namespace
Misc MISC
In the game
float GET_DISTANCE_BETWEEN_COORDS(float x1, float y1, float z1, float x2, float y2, float z2, BOOL useZ)
Hash
0xF1B760881820C952

Open in the interactive natives reference