Follow same format for polyZone.lua

Just better handling of polyZone scripts with less if statements
This commit is contained in:
Jim Shield
2025-08-13 18:27:07 +01:00
parent 06ef5cb53b
commit 345a81aaf7

View File

@@ -11,6 +11,65 @@
• removePolyZone(Location) - Removes a created zone. • removePolyZone(Location) - Removes a created zone.
]] ]]
local polyCreation = {
{
polyZoneScript = OXLibExport,
createPoly = function(data)
data.minZ = data.minZ or -20.0
data.maxZ = data.maxZ or 1000.0
data.thickness = ((data.maxZ / 2) - (data.minZ / 2)) * 2
local mid = data.maxZ - ((data.maxZ / 2) - (data.minZ / 2))
for i = 1, #data.points do
data.points[i] = vec3(data.points[i].x, data.points[i].y, mid)
end
return lib.zones.poly(data)
end,
createCircle = function(data)
return lib.zones.sphere(data)
end,
removeZone = function(Location)
Location:remove()
end,
},
{
polyZoneScript = "PolyZone",
createPoly = function(data)
local zone = PolyZone:Create(data.points, {
name = data.name,
minZ = data.minZ or nil,
maxZ = data.maxZ or nil,
debugPoly = data.debug
})
zone:onPlayerInOut(function(isPointInside)
if isPointInside then
data.onEnter()
else
data.onExit()
end
end)
return zone
end,
createCircle = function(data)
local zone = CircleZone:Create(data.coords, data.radius, { name = data.name, debugPoly = debugMode })
zone:onPlayerInOut(function(isPointInside)
if isPointInside then
data.onEnter()
else
data.onExit()
end
end)
return zone
end,
removeZone = function(Location)
Location:destroy()
end,
}
}
------------------------------------------------------------- -------------------------------------------------------------
-- Polygonal Zone Creation -- Polygonal Zone Creation
------------------------------------------------------------- -------------------------------------------------------------
@@ -41,41 +100,15 @@
---}) ---})
---``` ---```
function createPoly(data) function createPoly(data)
local Location = nil for _, script in ipairs(polyCreation) do
if isStarted(OXLibExport) then if isStarted(script.polyZoneScript) then
debugPrint("^6Bridge^7: ^2Creating new poly with ^7'^4"..OXLibExport.."^7': "..data.name) debugPrint("^6Bridge^7: ^2Creating new poly with ^7'^4"..script.polyZoneScript.."^7': "..data.name)
return script.createPoly(data)
data.minZ = data.minZ or -20.0 end
data.maxZ = data.maxZ or 1000.0
data.thickness = ((data.maxZ / 2) - (data.minZ / 2)) * 2
local mid = data.maxZ - ((data.maxZ / 2) - (data.minZ / 2))
for i = 1, #data.points do
data.points[i] = vec3(data.points[i].x, data.points[i].y, mid)
end end
Location = lib.zones.poly(data) print("^4ERROR^7: ^2No PolyZone creation script detected ^7")
return nil
elseif isStarted("PolyZone") then
debugPrint("^6Bridge^7: ^2Creating new poly with ^7'^4PolyZone^7': "..data.name)
Location = PolyZone:Create(data.points, {
name = data.name,
minZ = data.minZ or nil,
maxZ = data.maxZ or nil,
debugPoly = data.debug
})
Location:onPlayerInOut(function(isPointInside)
if isPointInside then
data.onEnter()
else
data.onExit()
end
end)
else
print("^4ERROR^7: ^2No PolyZone creation script detected ^7- ^2Check ^3exports^1.^2lua^7")
end
return Location
end end
------------------------------------------------------------- -------------------------------------------------------------
@@ -107,25 +140,16 @@ end
--- }) --- })
--- ``` --- ```
function createCirclePoly(data) function createCirclePoly(data)
local Location = nil for _, script in ipairs(polyCreation) do
if isStarted(OXLibExport) then if isStarted(script.polyZoneScript) then
debugPrint("^6Bridge^7: ^2Creating new ^3Cricle^2 poly with ^7"..OXLibExport.." "..data.name) debugPrint("^6Bridge^7: ^2Creating new ^3Cricle^2 poly with ^7"..script.polyZoneScript.." "..data.name)
Location = lib.zones.sphere(data)
elseif isStarted("PolyZone") then
debugPrint("^6Bridge^7: ^2Creating new ^3Cricle^2 poly with ^7PolyZone ".. data.name)
Location = CircleZone:Create(data.coords, data.radius, { name = data.name, debugPoly = debugMode })
Location:onPlayerInOut(function(isPointInside)
if isPointInside then
data.onEnter()
else
data.onExit()
end
end)
else
print("^4ERROR^7: ^2No PolyZone creation script detected ^7- ^2Check ^3starter^1.^2lua^7")
end
debugPrint("^6Bridge^7: ^2Zone Stats - Coords: "..formatCoord(data.coords).." Radius: "..data.radius) debugPrint("^6Bridge^7: ^2Zone Stats - Coords: "..formatCoord(data.coords).." Radius: "..data.radius)
return Location return script.createCircle(data)
end
end
print("^4ERROR^7: ^2No PolyZone creation script detected ^7")
return nil
end end
------------------------------------------------------------- -------------------------------------------------------------
@@ -145,11 +169,10 @@ end
--- removePolyZone(zone) --- removePolyZone(zone)
--- ``` --- ```
function removePolyZone(Location) function removePolyZone(Location)
if isStarted(OXLibExport) then for _, script in ipairs(polyCreation) do
debugPrint("^6Bridge^7: ^2Removing ^2poly with ^7"..OXLibExport) if isStarted(script.polyZoneScript) then
Location:remove() debugPrint("^6Bridge^7: ^2Removing ^3"..script.polyZoneScript.." ^2Zone^7")
elseif isStarted("PolyZone") then script.removeZone(Location)
debugPrint("^6Bridge^7: ^2poly with ^7PolyZone") end
Location:destroy()
end end
end end