DirkScripts Logo

Login With FiveM

Login

πŸ“š Library
β€Ί
Modules
β€Ί

closest

Closest

ℹ️ Shared Module - This can be used by both clients and the server

Single Closest

Find the single closest entity of a given type.

lua
local entity, distance = lib.closest.player()
local entity, distance = lib.closest.ped()
local entity, distance = lib.closest.vehicle()
local entity, distance = lib.closest.object()
ParameterTypeRequiredDescription
posvector3noOrigin position (defaults to player ped coords)
rangenumbernoMaximum search range
ignorenumbernoEntity to exclude from results
conditionfunctionnoFilter function fn(entity) β†’ boolean

ℹ️ lib.closest.ped() automatically filters out player peds β€” it only returns AI peds.

Example

lua
local ped, dist = lib.closest.ped(GetEntityCoords(cache.ped), 10.0)
if ped and dist < 3.0 then
    print('Found a ped nearby:', ped)
end

All In Range

Find all entities of a type within range.

lua
local entities, distances = lib.closest.all.player()
local entities, distances = lib.closest.all.ped()
local entities, distances = lib.closest.all.vehicle()
local entities, distances = lib.closest.all.object()

Returns an array of entities and a table of distances keyed by entity handle.

Example

lua
local vehicles, dists = lib.closest.all.vehicle(GetEntityCoords(cache.ped), 50.0)
for _, veh in ipairs(vehicles) do
    print('Vehicle', veh, 'at distance', dists[veh])
end

Copyright Β© 2026 DirkScripts.

Not affiliated with or endorsed by Rockstar North, Take-Two Interactive, or any other rights holders. FiveM is a copyright and registered trademark of Take-Two Interactive Software, Inc.
Our checkout system is provided by Tebex Limited, who manage payment processing, product delivery, and billing support. Prices shown in currencies other than GBP are approximate conversions updated daily. All purchases are processed in GBP, so the final amount charged may vary depending on your bank or payment provider’s exchange rate.