Zones
Spatial zones (sphere / box / poly) with enter / exit / inside callbacks — all sharing one tick.
Spatial zones (sphere / box / poly) with enter / exit / inside callbacks — all sharing one tick.
lib.zones creates spatial zones that fire onEnter / onExit / inside callbacks. Every
zone shares a single tick (via lib.grid), so there's no thread-per-zone cost. Callbacks are
client-side; the server exposes lookups.
Each returns a ZoneData with a :remove() method. Add debug = true to draw the zone.
lib.zones.sphere(data)local zone = lib.zones.sphere({
coords = vector3(215.7, -810.1, 30.7),
radius = 5.0,
onEnter = function(self) lib.print.info('in', self.id) end,
onExit = function(self) lib.print.info('out', self.id) end,
inside = function(self)
if IsControlJustPressed(0, 38) then print('E inside') end
end,
})radius defaults to 2.0; an optional thickness turns it into a flat cylinder.
lib.zones.box(data)lib.zones.box({
coords = vector3(100.0, 200.0, 30.0),
size = vector3(8.0, 4.0, 3.0),
rotation = math.rad(45),
onEnter = function(self) end,
})size defaults to vector3(4, 4, 4); rotation is in radians on Z; vertical thickness = size.z.
lib.zones.poly(data)lib.zones.poly({
points = {
vector3(0, 0, 30), vector3(10, 0, 30),
vector3(10, 10, 30), vector3(0, 10, 30),
},
thickness = 6.0,
})Needs 3+ points. coords (centroid) and radius are computed for you.
onEnterfun(self)optionalFired when the player enters the zone.
onExitfun(self)optionalFired when the player leaves.
insidefun(self)optionalFired every frame while inside — keep it light (e.g. an input check).
The server can't run callbacks, but it can query: lib.zones.getPlayerZones(source) returns
the zones containing a player, and lib.zones.isPlayerInZone(source, zoneId) is a boolean.
Callbacks are client-only. Enter / exit detection runs every ~300 ms (not instant); inside runs at frame rate, so keep it cheap. Always :remove() a zone you no longer need — a leaked zone keeps ticking. To move a zone, remove and recreate it.