mkafrin / PolyZone

PolyZone is a FiveM mod to define zones of different shapes and test whether a point is inside or outside of the zone
MIT License
202 stars 193 forks source link

Combo Zone principal #37

Closed coblyox closed 3 years ago

coblyox commented 3 years ago

Hi!

I don't know if it's a bug, but probably it should work that way. For example, if you teleport to different zone in same combo, it doesn't trigger PlayerInOut so for example I cannot get that zone metadata until I reenter zone. Maybe I'm just using it wrong?

For example:

local box1 = BoxZone:Create(vector3(344.37, -586.21, 28.8), 1, 1, {
  name="box1",
  debugPoly=false,
  minZ=27.8,
  maxZ=31.0,
  data={
      current = "box1"
  }
})

local box2 = BoxZone:Create(vector3(339.23, -584.14, 74.16), 1, 1, {
  name="box2",
  debugPoly=false,
  minZ=73.16,
  maxZ=75.16,
  data={
      current = "box2"
  }
})

local combo = ComboZone:Create({box1, box2}, {
    name="boxes",
    debugPoly=false
});

combo:onPlayerInOut(function(isPointInside, point, zone)
    if zone then
        print(zone.data.current)
        TriggerEvent('someEventWhichHandelsSameThing', zone.data)
    end
end)

If you enter any zone and teleport to other zone without leaving it (eg.: using SetEntityCoords() method). it's not retriggered and metadata is not updated. Like I said, maybe I'm using it the wrong way? Because as far wiki reaches, onPlayerInOut on individual zones doesn't return metadata. But maybe it could?

mkafrin commented 3 years ago

ComboZones by default stop at the first zone they find and don't register leaving unless you are in no zones. This is for optimization purposes. For use cases where this behavior is an obstacle, the 'exhaustive' helpers were added to ComboZones. These will go through all zones in the ComboZone no matter what and therefore always register entering/leaving, even when you have zones inside of each other. Please see this for more info on how to use them.

coblyox commented 3 years ago

Haven't read wiki properly, thank you for explanation.