zone

Named parts of the map: circles, boxes, polygons, terrain regions; enter / leave events (since API 3).

A zone is a named part of the map: a circle, a box, a polygon or the whole map, cut down by conditions (land or water, near water, ground height, slope, a height range). The hunter and, when asked, creatures fire zone_enter / zone_leave as they cross its edge. Zones also serve populations (where creatures live) and groups (territories, zones they avoid).

Zones made by a script are its own: they go when the scripts are reloaded (make them in main.lua; they stay from hunt to hunt). A mod's zones.json / populations.json makes them too (read again for every hunt). The guide: Zones, populations, herds and packs.

Functions

# zone.create(def) → Zone

since API 3

Makes a zone (or replaces the zone of that name).

ParameterType
deftablethe zone: name, a shape (circle = {x, z, radius}, box = {x1, z1, x2, z2}, polygon = {{x, z}, ...}, or none: the whole map), conditions (water = true / land = true, nearWater, awayFromWater, minHeight / maxHeight of the ground, maxSlope, minY / maxY of what is tested), areas / maps (only on these maps), tracking (hunter = false, creatures = true or {species = {...}, team = n, group = id, predator = bool})
Returns
Zone
-- the lake shore of one map: land within 2 km of water, inside a box
zone.create{name = "shore", box = {x1 = 60000, z1 = -90000, x2 = 90000, z2 = -60000},
            nearWater = 2000, land = true, areas = {2}}

# zone.circle(name, x, z, radius, opts?) → Zone

since API 3

A circle zone. Also zone.circle{name =, x =, z =, radius =, ...}.

ParameterType
namestring
xnumber
znumber
radiusnumber
opts optionaltablemore of the definition (conditions, tracking)
Returns
Zone
local x, _, z = player.pos()
local camp = zone.circle("camp", x, z, 3000, {creatures = {predator = true}})

# zone.box(name, x1, z1, x2, z2, opts?) → Zone

since API 3

A box zone (corners in any order).

ParameterType
namestring
x1number
z1number
x2number
z2number
opts optionaltablemore of the definition
Returns
Zone

# zone.polygon(name, points, opts?) → Zone

since API 3

A polygon zone.

ParameterType
namestring
pointstable{{x, z}, {x, z}, ...}: at least 3 corners
opts optionaltablemore of the definition
Returns
Zone

# zone.terrain(name, opts) → Zone

since API 3

A terrain region: the whole map where the conditions hold.

ParameterType
namestring
optstableits conditions (water, nearWater, minHeight ...)
Returns
Zone
zone.terrain("lakes", {water = true})
zone.terrain("highlands", {minHeight = 9000, maxSlope = 0.6})

# zone.get(name) → Zone|nil

since API 3

A zone by name.

ParameterType
namestring|Zone
Returns
Zone|nil

# zone.list() → table

since API 3

Every zone (of every mod, also the ones of other maps).

Returns
tablea list of Zone

# zone.remove(zone) → boolean

since API 3

Removes a zone.

ParameterType
zonestring|Zone
Returns
booleanfalse when there was no such zone

# zone.at(x, z) → table

since API 3

The zones of this map that contain a point.

ParameterType
xnumber
znumber
Returns
tablea list of Zone

Zone

A handle to one zone (zone.circle, zone.get ...). Handles compare equal when they are the same zone.

Fields

FieldTypeAccess
namestringreadits name (unique: a zone made with a name that exists replaces that one)
kindstringread"circle", "box", "polygon" or "map" (a terrain region)
validbooleanreadfalse once it was removed (or the scripts were reloaded)
idintegerreada number for it
hunterInsidebooleanreadthe hunter is in it right now
activebooleanreadit exists on this hunt's map (areas / maps)
modstringreadthe mod that made it
xnumber?read / writecircle: its middle (writable)
znumber?read / writecircle: its middle (writable)
radiusnumber?read / writecircle: its radius (writable: a ring that shrinks, a camp that moves; who is inside is kept, and the next frame fires zone_enter / zone_leave for what the new circle takes in or leaves out)

Methods

# z:contains(x, z, y?) → boolean

since API 3

Whether a point is in the zone: its shape and all its conditions.

ParameterType
xnumber
znumber
y optionalnumbera height for the height range (default: the ground)
Returns
boolean

# z:creatures(filter?) → table

hunt only since API 3

The creatures in the zone (living ones by default).

ParameterType
filter optionalstring|tablea species, or {species =, team =, dead =, all =}
Returns
tablea list of Creature

# z:count(filter?) → integer

hunt only since API 3

How many creatures are in the zone.

ParameterType
filter optionalstring|tableas z:creatures
Returns
integer

# z:randomPoint(opts?) → number?, number?

hunt only since API 3

A random point of the zone that meets its conditions and these.

ParameterType
opts optionaltableconditions as world.randomPoint (on land by default)
Returns
number?x
number?z

# z:center() → number, number

since API 3

Its middle.

Returns
numberx
numberz

# z:bounds() → number, number, number, number

since API 3

The box around it.

Returns
numberx1
numberz1
numberx2
numberz2

# z:set(fields)

since API 3

Moves or resizes a circle zone in one call (as writing z.x, z.z, z.radius).

ParameterType
fieldstable{x =, z =, radius =}, any of them
-- the arena's ring shrinks by 10 % every 20 seconds
timer.every(20, function() ring:set{radius = ring.radius * 0.9} end)

# z:remove() → boolean

since API 3

Removes the zone (as zone.remove(z)).

Returns
booleanfalse when it was removed already