Skip to content

Commit 4188bd2

Browse files
committed
feat(zones): add getNearbyZones
1 parent 0b9f6e0 commit 4188bd2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

imports/zones/shared.lua

+7-6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ end
100100
local insideZones = lib.context == 'client' and {} --[[@as table<number, CZone>]]
101101
local exitingZones = lib.context == 'client' and lib.array:new() --[[@as Array<CZone>]]
102102
local enteringZones = lib.context == 'client' and lib.array:new() --[[@as Array<CZone>]]
103+
local nearbyZones = lib.array:new() --[[@as Array<CZone>]]
103104
local glm_polygon_contains = glm.polygon.contains
104105
local tick
105106

@@ -120,23 +121,21 @@ end
120121
CreateThread(function()
121122
if lib.context == 'server' then return end
122123

123-
local lastZones = {}
124-
125124
while true do
126125
local coords = GetEntityCoords(cache.ped)
127-
local zones = lib.grid.getNearbyEntries(coords, function(entry) return entry.remove == removeZone end) --[[@as CZone[] ]]
126+
local zones = lib.grid.getNearbyEntries(coords, function(entry) return entry.remove == removeZone end) --[[@as Array<CZone>]]
128127
local cellX, cellY = lib.grid.getCellPosition(coords)
129128
cache.coords = coords
130129

131130
if cellX ~= cache.lastCellX or cellY ~= cache.lastCellY then
132-
for i = 1, #lastZones do
133-
local zone = lastZones[i]
131+
for i = 1, #nearbyZones do
132+
local zone = nearbyZones[i]
134133

135134
zone.insideZone = false
136135
insideZones[zone.id] = nil
137136
end
138137

139-
lastZones = zones
138+
nearbyZones = zones
140139
cache.lastCellX = cellX
141140
cache.lastCellY = cellY
142141
end
@@ -467,4 +466,6 @@ function lib.zones.getAllZones() return Zones end
467466

468467
function lib.zones.getCurrentZones() return insideZones end
469468

469+
function lib.zones.getNearbyZones() return nearbyZones end
470+
470471
return lib.zones

0 commit comments

Comments
 (0)