mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
feat(points): get closest point
This commit is contained in:
@@ -5,11 +5,13 @@ local function removePoint(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local nearby = {}
|
local nearby = {}
|
||||||
|
local closest
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
local coords = GetEntityCoords(cache.ped)
|
local coords = GetEntityCoords(cache.ped)
|
||||||
Wait(300)
|
Wait(300)
|
||||||
|
closest = nil
|
||||||
table.wipe(nearby)
|
table.wipe(nearby)
|
||||||
|
|
||||||
for _, point in pairs(points) do
|
for _, point in pairs(points) do
|
||||||
@@ -18,6 +20,10 @@ CreateThread(function()
|
|||||||
if distance <= point.distance then
|
if distance <= point.distance then
|
||||||
point.currentDistance = distance
|
point.currentDistance = distance
|
||||||
|
|
||||||
|
if distance < (closest?.currentDistance or point.distance) then
|
||||||
|
closest = point
|
||||||
|
end
|
||||||
|
|
||||||
if point.nearby then
|
if point.nearby then
|
||||||
nearby[#nearby + 1] = point
|
nearby[#nearby + 1] = point
|
||||||
end
|
end
|
||||||
@@ -64,5 +70,9 @@ return {
|
|||||||
points[id] = self
|
points[id] = self
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
end,
|
||||||
|
|
||||||
|
closest = function()
|
||||||
|
return closest
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user