Closed cademullen closed 3 years ago
function createHouseZones(points) for k, v in pairs(points) do local _coords, isInsidePrevious = vector3(v["Coords"].enter.x, v["Coords"].enter.y, v["Coords"].enter.z), false
local newzone = #zones + 1
zones[newzone] = BoxZone:Create(_coords, 1.5, 1.5, {
name = ('houseZone-%s'):format(newzone), data = { v }, useZ = true, maxZ = v["Coords"].enter.z + 1.5, minZ = v["Coords"].enter.z - 1.5 , heading = v["Coords"].enter.h, debugPoly = true
})
end
comboZone = ComboZone:Create(zones, { name = 'houseZones' })
comboZone:onPlayerInOutExhaustive(function(isPointInside, point, insideZones, enterZones, leftZones)
if enterZones then
for i=1, #enterZones do
print(tprint(enterZones[i].data))
createPlayerInteractions(i, enterZones[i].data)
isInAZone = true
inCurrentZone = enterZones[i]
break;
end
end
if leftZones then
for i=1, #leftZones do
isInAZone = false
end
end
end)
end
Im trying to get the player interaction for each zone they enter. I do have this when a new zone gets created
function addHouse(point)
local newzone = #zones + 1
zones[newzone] = BoxZone:Create(_coords, 1.5, 1.5, {
name = ('houseZone-%s'):format(newzone), data = { point }, useZ = true, maxZ = point["Coords"].enter.z + 1.5, minZ = point["Coords"].enter.z - 1.5 , heading = point["Coords"].enter.h, debugPoly = true
})
ComboZone:AddZone(inCurrentZone)
end
AddZone adds a new zone to the ComboZone. You don't need a separate zones table if you use AddZone since you can just pass the zones into it directly. See the below update of your code.
function createHouseZones(points)
comboZone = ComboZone:Create({}, {name = "houseZones"})
for k, v in pairs(points) do
local _coords, isInsidePrevious = vector3(v["Coords"].enter.x, v["Coords"].enter.y, v["Coords"].enter.z), false
comboZone:AddZone(BoxZone:Create(_coords, 1.5, 1.5, {
name = ("houseZone-%s"):format(newzone),
data = {v},
useZ = true,
maxZ = v["Coords"].enter.z + 1.5,
minZ = v["Coords"].enter.z - 1.5,
heading = v["Coords"].enter.h,
debugPoly = true
}))
end
comboZone:onPlayerInOutExhaustive(
function(isPointInside, point, insideZones, enterZones, leftZones)
if enterZones then
for i = 1, #enterZones do
print(tprint(enterZones[i].data))
createPlayerInteractions(i, enterZones[i].data)
isInAZone = true
inCurrentZone = enterZones[i]
break
end
end
if leftZones then
for i = 1, #leftZones do
isInAZone = false
end
end
end
)
end
function addHouse(point)
local _coords = vector3(v["Coords"].enter.x, v["Coords"].enter.y, v["Coords"].enter.z)
local newZone = BoxZone:Create(_coords, 1.5, 1.5, {
name = ("houseZone-%s"):format(newzone),
data = {point},
useZ = true,
maxZ = point["Coords"].enter.z + 1.5,
minZ = point["Coords"].enter.z - 1.5,
heading = point["Coords"].enter.h,
debugPoly = true
})
ComboZone:AddZone(newZone)
end
Ahh that makes sense, but I do get this error.
SCRIPT ERROR: @polyzone/ComboZone.lua:172: attempt to get length of a nil value (local 'zones')
Oh in addHouse
ComboZone:AddZone(newZone)
should instead be
comboZone:AddZone(newZone)
Yeah that was it appreciate the help. Do you have a discord that I could join, so if there are just some small questions I could contact you?
Nah sorry, no Polyzone discord. Not nearly enough traffic to justify it. Feel free to just make an issue though, after checking the wiki.
Could I get some examples on ComboZone AddZone().