2022-03-13 03:22:09 +00:00
|
|
|
local points = {}
|
|
|
|
|
|
2022-04-14 10:58:17 +00:00
|
|
|
local function removePoint(self)
|
|
|
|
|
points[self.id] = nil
|
2022-03-13 03:22:09 +00:00
|
|
|
end
|
|
|
|
|
|
2022-04-14 10:58:17 +00:00
|
|
|
local nearby = {}
|
2022-04-14 11:08:56 +00:00
|
|
|
local closest
|
2022-04-14 10:58:17 +00:00
|
|
|
|
2022-03-13 03:22:09 +00:00
|
|
|
CreateThread(function()
|
|
|
|
|
while true do
|
|
|
|
|
local coords = GetEntityCoords(cache.ped)
|
|
|
|
|
Wait(300)
|
2022-04-14 11:08:56 +00:00
|
|
|
closest = nil
|
2022-03-13 03:22:09 +00:00
|
|
|
table.wipe(nearby)
|
|
|
|
|
|
2022-04-14 10:58:17 +00:00
|
|
|
for _, point in pairs(points) do
|
2022-03-13 03:22:09 +00:00
|
|
|
local distance = #(coords - point.coords)
|
|
|
|
|
|
|
|
|
|
if distance <= point.distance then
|
|
|
|
|
point.currentDistance = distance
|
2022-03-16 01:18:10 +00:00
|
|
|
|
2022-04-14 11:08:56 +00:00
|
|
|
if distance < (closest?.currentDistance or point.distance) then
|
|
|
|
|
closest = point
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-25 10:58:46 +00:00
|
|
|
if point.nearby then
|
2022-03-25 10:38:32 +00:00
|
|
|
nearby[#nearby + 1] = point
|
|
|
|
|
end
|
|
|
|
|
|
2022-03-16 01:18:10 +00:00
|
|
|
if point.onEnter and not point.inside then
|
|
|
|
|
point.inside = true
|
|
|
|
|
point:onEnter()
|
|
|
|
|
end
|
2022-03-13 03:22:09 +00:00
|
|
|
elseif point.currentDistance then
|
|
|
|
|
if point.onExit then point:onExit() end
|
2022-03-16 01:18:10 +00:00
|
|
|
point.inside = nil
|
2022-03-13 03:22:09 +00:00
|
|
|
point.currentDistance = nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
CreateThread(function()
|
|
|
|
|
while true do
|
|
|
|
|
Wait(0)
|
|
|
|
|
for i = 1, #nearby do
|
2022-03-25 10:58:46 +00:00
|
|
|
nearby[i]:nearby()
|
2022-03-13 03:22:09 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
2022-04-14 10:58:17 +00:00
|
|
|
return {
|
|
|
|
|
new = function(coords, distance, data)
|
|
|
|
|
local id = #points + 1
|
|
|
|
|
|
|
|
|
|
local self = {
|
|
|
|
|
id = id,
|
|
|
|
|
coords = coords,
|
|
|
|
|
distance = distance,
|
|
|
|
|
remove = removePoint,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if data then
|
|
|
|
|
for k, v in pairs(data) do
|
|
|
|
|
self[k] = v
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
points[id] = self
|
|
|
|
|
|
|
|
|
|
return self
|
2022-04-14 11:08:56 +00:00
|
|
|
end,
|
|
|
|
|
|
|
|
|
|
closest = function()
|
|
|
|
|
return closest
|
2022-04-14 10:58:17 +00:00
|
|
|
end
|
|
|
|
|
}
|