getNearestPed

Finds the nearest NPC ped within the specified distance.

Parameters:

  • coords (vector3, optional): The coordinates to search from. Defaults to player's current position.

  • distance (number, optional): Maximum search distance in units. Defaults to 10.0.

Returns:

  • ped (entity): The nearest ped entity, or 'no nearby ped' if none found

  • distance (number): Distance to the nearest ped, or 'no nearby ped' if none found

Example:

local nearestPed, pedDistance = ps.getNearestPed()
if nearestPed ~= 'no nearby ped' then
    print("Found ped at distance: " .. pedDistance)
end

-- With custom parameters
local coords = vector3(100.0, 200.0, 30.0)
local ped, dist = ps.getNearestPed(coords, 15.0)

Last updated