mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
tweak(client/points): set point.isClosest
This commit is contained in:
@@ -3,22 +3,26 @@
|
|||||||
---@field coords vector3
|
---@field coords vector3
|
||||||
---@field distance number
|
---@field distance number
|
||||||
---@field currentDistance number
|
---@field currentDistance number
|
||||||
|
---@field isClosest boolean?
|
||||||
---@field remove fun()
|
---@field remove fun()
|
||||||
---@field onEnter fun(self: CPoint)?
|
---@field onEnter fun(self: CPoint)?
|
||||||
---@field onExit fun(self: CPoint)?
|
---@field onExit fun(self: CPoint)?
|
||||||
---@field nearby fun(self: CPoint)?
|
---@field nearby fun(self: CPoint)?
|
||||||
|
|
||||||
local points = {}
|
local points = {}
|
||||||
|
|
||||||
local function removePoint(self)
|
|
||||||
points[self.id] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local nearbyPoints = {}
|
local nearbyPoints = {}
|
||||||
local nearbyCount = 0
|
local nearbyCount = 0
|
||||||
local closestPoint
|
local closestPoint
|
||||||
local tick
|
local tick
|
||||||
|
|
||||||
|
local function removePoint(self)
|
||||||
|
if closestPoint?.id == self.id then
|
||||||
|
closestPoint = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
points[self.id] = nil
|
||||||
|
end
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
if nearbyCount ~= 0 then
|
if nearbyCount ~= 0 then
|
||||||
@@ -28,7 +32,10 @@ CreateThread(function()
|
|||||||
|
|
||||||
local coords = GetEntityCoords(cache.ped)
|
local coords = GetEntityCoords(cache.ped)
|
||||||
cache.coords = coords
|
cache.coords = coords
|
||||||
|
|
||||||
|
if closestPoint and #(coords - closestPoint.coords) > closestPoint.distance then
|
||||||
closestPoint = nil
|
closestPoint = nil
|
||||||
|
end
|
||||||
|
|
||||||
for _, point in pairs(points) do
|
for _, point in pairs(points) do
|
||||||
local distance = #(coords - point.coords)
|
local distance = #(coords - point.coords)
|
||||||
@@ -36,8 +43,14 @@ CreateThread(function()
|
|||||||
if distance <= point.distance then
|
if distance <= point.distance then
|
||||||
point.currentDistance = distance
|
point.currentDistance = distance
|
||||||
|
|
||||||
---@diagnostic disable-next-line: need-check-nil
|
if closestPoint then
|
||||||
if distance < (closestPoint?.currentDistance or point.distance) then
|
if distance < closestPoint.currentDistance then
|
||||||
|
closestPoint.isClosest = nil
|
||||||
|
point.isClosest = true
|
||||||
|
closestPoint = point
|
||||||
|
end
|
||||||
|
elseif distance < point.distance then
|
||||||
|
point.isClosest = true
|
||||||
closestPoint = point
|
closestPoint = point
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user