PedClient1 output

getClosestPed

GET_CLOSEST_PED0xC33AB876A77F8164

The GTA V native GET_CLOSEST_PED of the PED namespace, as LS:MP client scripts call it: the global function getClosestPed, in JavaScript and in Lua.

SignatureJavaScript
getClosestPed(
  x: number,
  y: number,
  z: number,
  radius: number,
  p4: boolean,
  p5: boolean,
  p7: boolean,
  p8: boolean,
  pedType: number
): [ok: boolean, outPed: Ped]
SignatureLua
getClosestPed(
  x: number,
  y: number,
  z: number,
  radius: number,
  p4: boolean,
  p5: boolean,
  p7: boolean,
  p8: boolean,
  pedType: integer
): boolean, Ped

Usage

JavaScript
const [ok, outPed] = getClosestPed(x, y, z, radius, p4, p5, p7, p8, pedType);
Lua
local ok, outPed = getClosestPed(x, y, z, radius, p4, p5, p7, p8, pedType)

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 [ok, outPed] = getClosestPed(pos, radius, p4, p5, p7, p8, pedType);
Lua · with vectors
local ok, outPed = getClosestPed(pos, radius, p4, p5, p7, p8, pedType)

Parameters

ParameterTypeJavaScriptLua
xfloatnumbernumber
yfloatnumbernumber
zfloatnumbernumber
radiusfloatnumbernumber
p4BOOLbooleanboolean
p5BOOLbooleanboolean
p7BOOLbooleanboolean
p8BOOLbooleanboolean
pedTypeintnumberinteger

Returns

2 values, in this order: an array in JavaScript, multiple return values in Lua.

#ValueTypeJavaScriptLuaDescription
1okBOOLbooleanbooleanThe native’s own return value.
2outPedPednumberintegeroutput

Notes

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

Gets the closest ped in a radius.

Ped Types:
Any ped = -1
Player = 1
Male = 4
Female = 5
Cop = 6
Human = 26
SWAT = 27
Animal = 28
Army = 29


P4 P5 P7 P8
1 0 x x = return nearest walking Ped
1 x 0 x = return nearest walking Ped
x 1 1 x = return Ped you are using
0 0 x x = no effect
0 x 0 x = no effect

x = can be 1 or 0. Does not have any obvious changes.

This function does not return ped who is:
1. Standing still
2. Driving
3. Fleeing
4. Attacking

This function only work if the ped is:
1. walking normally.
2. waiting to cross a road.

Note: getPedNearbyPeds works for more peds.

Reference

Namespace
Ped PED
In the game
BOOL GET_CLOSEST_PED(float x, float y, float z, float radius, BOOL p4, BOOL p5, Ped* outPed, BOOL p7, BOOL p8, int pedType)
Hash
0xC33AB876A77F8164

Open in the interactive natives reference