mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
feat(zones): add getNearbyZones
This commit is contained in:
@@ -100,6 +100,7 @@ end
|
|||||||
local insideZones = lib.context == 'client' and {} --[[@as table<number, CZone>]]
|
local insideZones = lib.context == 'client' and {} --[[@as table<number, CZone>]]
|
||||||
local exitingZones = lib.context == 'client' and lib.array:new() --[[@as Array<CZone>]]
|
local exitingZones = lib.context == 'client' and lib.array:new() --[[@as Array<CZone>]]
|
||||||
local enteringZones = lib.context == 'client' and lib.array:new() --[[@as Array<CZone>]]
|
local enteringZones = lib.context == 'client' and lib.array:new() --[[@as Array<CZone>]]
|
||||||
|
local nearbyZones = lib.array:new() --[[@as Array<CZone>]]
|
||||||
local glm_polygon_contains = glm.polygon.contains
|
local glm_polygon_contains = glm.polygon.contains
|
||||||
local tick
|
local tick
|
||||||
|
|
||||||
@@ -120,23 +121,21 @@ end
|
|||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
if lib.context == 'server' then return end
|
if lib.context == 'server' then return end
|
||||||
|
|
||||||
local lastZones = {}
|
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local coords = GetEntityCoords(cache.ped)
|
local coords = GetEntityCoords(cache.ped)
|
||||||
local zones = lib.grid.getNearbyEntries(coords, function(entry) return entry.remove == removeZone end) --[[@as CZone[] ]]
|
local zones = lib.grid.getNearbyEntries(coords, function(entry) return entry.remove == removeZone end) --[[@as Array<CZone>]]
|
||||||
local cellX, cellY = lib.grid.getCellPosition(coords)
|
local cellX, cellY = lib.grid.getCellPosition(coords)
|
||||||
cache.coords = coords
|
cache.coords = coords
|
||||||
|
|
||||||
if cellX ~= cache.lastCellX or cellY ~= cache.lastCellY then
|
if cellX ~= cache.lastCellX or cellY ~= cache.lastCellY then
|
||||||
for i = 1, #lastZones do
|
for i = 1, #nearbyZones do
|
||||||
local zone = lastZones[i]
|
local zone = nearbyZones[i]
|
||||||
|
|
||||||
zone.insideZone = false
|
zone.insideZone = false
|
||||||
insideZones[zone.id] = nil
|
insideZones[zone.id] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
lastZones = zones
|
nearbyZones = zones
|
||||||
cache.lastCellX = cellX
|
cache.lastCellX = cellX
|
||||||
cache.lastCellY = cellY
|
cache.lastCellY = cellY
|
||||||
end
|
end
|
||||||
@@ -467,4 +466,6 @@ function lib.zones.getAllZones() return Zones end
|
|||||||
|
|
||||||
function lib.zones.getCurrentZones() return insideZones end
|
function lib.zones.getCurrentZones() return insideZones end
|
||||||
|
|
||||||
|
function lib.zones.getNearbyZones() return nearbyZones end
|
||||||
|
|
||||||
return lib.zones
|
return lib.zones
|
||||||
|
|||||||
Reference in New Issue
Block a user