Skip to content

Zones

A zone is a box between two corners, or a circle around a point with any height unless zMin < zMax is given. The server tests every player in the world against every zone once per tick and calls OnPlayerEnterZone(pid, zone) / OnPlayerLeaveZone(pid, zone) on the edges. Ids start at 1.

Function
CreateZone(x1, y1, z1, x2, y2, z2)id | nil a box between two corners
CreateCircleZone(x, y, radius [, zMin, zMax])id | nil a circle; any height unless the bounds are given
DestroyZone(id)
IsPlayerInZone(pid, id)
IsPointInZone(id, x, y, z)
GetZonePlayers(id){pid, ...}
GetPlayerZones(pid){id, ...}
GetZones(){id, ...}
GetZoneInfo(id){circle, minX, minY, minZ, maxX, maxY, maxZ, x, y, radius} | nil
SetZoneData(id, key, value), GetZoneData(id, key) a bag per zone, cleared with the zone

“Leaving” is every way out: walking, being moved (SetPlayerPos), a despawn, a respawn elsewhere, a disconnect. The position tested is the player’s position of record — where the server has them, not where their client is drawing them this frame.

local arena = CreateZone(1200, 1000, 0, 1260, 1060, 40)
function OnPlayerEnterZone(pid, zone)
if zone == arena then
GameText(pid, "The arena", 1500, GAMETEXT_LOWER)
SetZoneData(zone, "last", GetPlayerName(pid))
end
end
function OnPlayerLeaveZone(pid, zone)
if zone == arena and #GetZonePlayers(zone) == 0 then
SendClientMessageToAll(COLOUR_SERVER, "the arena is empty")
end
end

A hot reload tears every zone down; create them in OnGameModeInit.