Files
ox_lib/imports/points/client.lua

79 lines
1.3 KiB
Lua
Raw Normal View History

local points = {}
2022-04-14 10:58:17 +00:00
local function removePoint(self)
points[self.id] = nil
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
CreateThread(function()
while true do
local coords = GetEntityCoords(cache.ped)
Wait(300)
2022-04-14 11:08:56 +00:00
closest = nil
table.wipe(nearby)
2022-04-14 10:58:17 +00:00
for _, point in pairs(points) do
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
if point.nearby then
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
elseif point.currentDistance then
if point.onExit then point:onExit() end
2022-03-16 01:18:10 +00:00
point.inside = nil
point.currentDistance = nil
end
end
end
end)
CreateThread(function()
while true do
Wait(0)
for i = 1, #nearby do
nearby[i]:nearby()
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
}