DirkScripts
Docs
Closest
βΉοΈ Shared Module - This can be used by both clients and the server
#Single Closest
Find the single closest entity of a given type.
lualocal entity, distance = lib.closest.player() local entity, distance = lib.closest.ped() local entity, distance = lib.closest.vehicle() local entity, distance = lib.closest.object()
| Parameter | Type | Required | Description |
|---|---|---|---|
| pos | vector3 | no | Origin position (defaults to player ped coords) |
| range | number | no | Maximum search range |
| ignore | number | no | Entity to exclude from results |
| condition | function | no | Filter function fn(entity) β boolean |
βΉοΈ lib.closest.ped() automatically filters out player peds β it only returns AI peds.
#Example
lualocal 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.
lualocal 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
lualocal 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
