ObjectClient

getClosestObjectOfType

GET_CLOSEST_OBJECT_OF_TYPE0xE143FA2249364369

The GTA V native GET_CLOSEST_OBJECT_OF_TYPE of the OBJECT namespace, as LS:MP client scripts call it: the global function getClosestObjectOfType, in JavaScript and in Lua.

SignatureJavaScript
getClosestObjectOfType(
  x: number,
  y: number,
  z: number,
  radius: number,
  modelHash: Hash,
  isMission: boolean,
  p6: boolean,
  p7: boolean
): Object
SignatureLua
getClosestObjectOfType(
  x: number,
  y: number,
  z: number,
  radius: number,
  modelHash: Hash,
  isMission: boolean,
  p6: boolean,
  p7: boolean
): Object

Usage

JavaScript
const object = getClosestObjectOfType(x, y, z, radius, modelHash, isMission, p6, p7);
Lua
local object = getClosestObjectOfType(x, y, z, radius, modelHash, isMission, p6, p7)

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 object = getClosestObjectOfType(pos, radius, modelHash, isMission, p6, p7);
Lua · with vectors
local object = getClosestObjectOfType(pos, radius, modelHash, isMission, p6, p7)

Parameters

ParameterTypeJavaScriptLua
xfloatnumbernumber
yfloatnumbernumber
zfloatnumbernumber
radiusfloatnumbernumber
modelHashHashnumberinteger
isMissionBOOLbooleanboolean
p6BOOLbooleanboolean
p7BOOLbooleanboolean

Returns

Object JavaScript number, Lua integer

Game handle of an object (prop). Not an LS:MP netId. Convert one with lsmp.getEntityFromNetId.

Notes

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

Has 8 params in the latest patches.

isMission - if true doesn't return mission objects

Reference

Namespace
Object OBJECT
In the game
Object GET_CLOSEST_OBJECT_OF_TYPE(float x, float y, float z, float radius, Hash modelHash, BOOL isMission, BOOL p6, BOOL p7)
Hash
0xE143FA2249364369

Open in the interactive natives reference