diff --git a/imports/points/client.lua b/imports/points/client.lua index c8608d4..e763523 100644 --- a/imports/points/client.lua +++ b/imports/points/client.lua @@ -33,11 +33,6 @@ end CreateThread(function() while true do - if nearbyCount ~= 0 then - table.wipe(nearbyPoints) - nearbyCount = 0 - end - local coords = GetEntityCoords(cache.ped) local newPoints = lib.grid.getNearbyEntries(coords, function(entry) return entry.remove == removePoint end) --[[@as CPoint[] ]] local cellX, cellY = lib.grid.getCellPosition(coords) @@ -45,7 +40,7 @@ CreateThread(function() closestPoint = nil if cellX ~= cache.lastCellX or cellY ~= cache.lastCellY then - for i = 1, #nearbyPoints do + for i = 1, nearbyCount do local point = nearbyPoints[i] if point.inside then @@ -64,6 +59,11 @@ CreateThread(function() cache.lastCellY = cellY end + if nearbyCount ~= 0 then + table.wipe(nearbyPoints) + nearbyCount = 0 + end + for i = 1, #newPoints do local point = newPoints[i] local distance = #(coords - point.coords) @@ -78,10 +78,8 @@ CreateThread(function() closestPoint = point end - if point.nearby then - nearbyCount += 1 - nearbyPoints[nearbyCount] = point - end + nearbyCount += 1 + nearbyPoints[nearbyCount] = point if point.onEnter and not point.inside then point.inside = true