mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
fix(zones/client): do not overwrite zone.distance with contains
Manually calling the contains method would overwrite zone distance. Also move Wait to the end of the thread to prevent race conditions.
This commit is contained in:
@@ -223,13 +223,13 @@ local tick
|
|||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
Wait(300)
|
|
||||||
local coords = GetEntityCoords(cache.ped)
|
local coords = GetEntityCoords(cache.ped)
|
||||||
table.wipe(inside)
|
table.wipe(inside)
|
||||||
insideCount = 0
|
insideCount = 0
|
||||||
|
|
||||||
for _, zone in pairs(Zones) do
|
for _, zone in pairs(Zones) do
|
||||||
local contains = zone:contains(coords)
|
local contains = zone:contains(coords)
|
||||||
|
zone.distance = #(zone.coords - coords)
|
||||||
|
|
||||||
if contains then
|
if contains then
|
||||||
if zone.onEnter and not zone.insideZone then
|
if zone.onEnter and not zone.insideZone then
|
||||||
@@ -275,6 +275,8 @@ CreateThread(function()
|
|||||||
elseif insideCount == 0 then
|
elseif insideCount == 0 then
|
||||||
tick = ClearInterval(tick)
|
tick = ClearInterval(tick)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Wait(300)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -302,13 +304,11 @@ end
|
|||||||
local glm_polygon_contains = glm.polygon.contains
|
local glm_polygon_contains = glm.polygon.contains
|
||||||
|
|
||||||
local function contains(self, coords)
|
local function contains(self, coords)
|
||||||
self.distance = #(self.coords - coords)
|
|
||||||
return glm_polygon_contains(self.polygon, coords, self.thickness / 4)
|
return glm_polygon_contains(self.polygon, coords, self.thickness / 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function insideSphere(self, coords)
|
local function insideSphere(self, coords)
|
||||||
self.distance = #(self.coords - coords)
|
return #(self.coords - coords) < self.radius
|
||||||
return self.distance < self.radius
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user