zones
Server
modkit.zones holds named areas on the map. The server checks every living player against all zones in the half-second sweep and fires zoneEnter and zoneLeave. Zones are shared by all resources and are gone after a restart, so create them when your resource starts.
Positions are Unreal units, 100 units are one metre. A zone is flat, it covers every height unless you give minZ or maxZ. The limit is 512 zones.
modkit.zones.add
modkit.zones.add(zone)
| Field | Type | Description |
|---|---|---|
name |
string | unique name. Adding the same name again replaces the zone. |
shape |
string | "circle" (default) or "polygon" |
x, y, radius |
number | circle only |
points |
array | polygon only, 3 to 256 corners as { x = , y = } or { x, y }. The polygon may be concave. |
minZ, maxZ |
number | optional height limits |
blockDamage |
boolean | attacks do no damage when the attacker or the victim stands in the zone |
damagePerSecond |
number | health every living player inside loses per second. A player who reaches 0 dies. |
data |
any | your own value, returned with the zone. Tables, strings, numbers and booleans. |
Returns: true, or false when the zone limit is reached. Missing or wrong fields raise an error.
modkit.zones.add({ name = "sanctuary", shape = "circle", x = -215000, y = 48000, radius = 15000, blockDamage = true })
modkit.zones.add({
name = "swamp",
shape = "polygon",
points = { { x = 0, y = 0 }, { x = 30000, y = 0 }, { x = 30000, y = 20000 }, { x = 0, y = 20000 } },
data = { label = "Eastern swamp" },
})
blockDamage works by skipping the game's ApplyDamage call. The plugin sees that call for player dinosaurs and for AI spawned with modkit.ai. Attacks by the game's own AI of a species that no player has played since the server started may still do damage.
modkit.zones.remove, clear
modkit.zones.remove(name) returns true when the zone existed. No zoneLeave fires for players who were inside.
modkit.zones.clear() removes every zone.
modkit.zones.get, list
modkit.zones.get(name) returns the zone table or nil.
modkit.zones.list() returns all zones.
The table has the fields you passed to add.
modkit.zones.at
modkit.zones.at(x, y [, z])
Returns: array with the names of all zones that contain the point. z defaults to 0.
local x, y, z = player:pos()
for _, name in ipairs(modkit.zones.at(x, y, z)) do print(player.name .. " is in " .. name) end
modkit.zones.playersIn
modkit.zones.playersIn(name)
Returns: array of player tables that were inside the zone at the last sweep.
Events zoneEnter, zoneLeave
zoneEnter(player, zone) and zoneLeave(player, zone). zone is the zone table. A player who dies, disconnects or loses the dinosaur leaves all zones. For a disconnected player the player table only carries the Steam ID.
modkit.events.add("zoneEnter", function(player, zone)
if zone.name == "sanctuary" then player:notify("You entered the sanctuary. No fighting here.") end
end)