Experimental

An early preview: docs, the API and the dashboard may change or break.

Report a problem

types.Region

A region of the world. Its entered and left signals fire as players cross its edge.

Signals

region.entered: types.Signal<types.Player>
#
read only

Fires when a player walks into the region.

region.interacting: types.Intercept<types.InteractEvent>
#
read only

Runs before a player uses a map block inside the region; return false to stop it. Item use still happens.

region.left: types.Signal<types.Player>
#
read only

Fires when a player walks out of the region or leaves while in it.

Fields

region.alive: boolean
#
read only

False once the region has been removed.

region.name: string
#
read only

The region's name; several regions can share one.

region.players: { types.Player }
#
read only

The players inside the region as of this tick.

local world = require("@ember/world")

-- King of the hill: once a second, whoever stands alone on the hill scores.
local hill = world.regions.single("hill")
local points: { [string]: number } = {}

task.spawn(function()
	while true do
		task.wait(1)
		if #hill.players == 1 then
			local king = hill.players[1]
			points[king.id] = (points[king.id] or 0) + 1
			king:send(`<gold>King of the hill: {points[king.id]}`)
		end
	end
end)
region.properties: { [string]: string }
#
read only

The text properties set on it in the editor or by world.regions.create.

region.shape: types.Shape
#
read only

The area the region covers.

Methods

region:contains(position: vector) -> boolean
#

Returns whether a position is inside the region.

region:remove()
#

Removes the region. Its signals stop and its players list empties.

region:reshape(shape: types.Shape)
#

Changes the region's shape; who is inside updates on the next tick.

local players = require("@ember/players")
local ui = require("@ember/ui")
local world = require("@ember/world")

-- A shrinking zone: every 10 seconds the circle closes in, and anyone outside it takes damage.
local center = world.markers.single("zone_center").position
local radius = 80
local zone = world.regions.create("zone", { kind = "cylinder", base = center - vector.create(0, 64, 0), radius = radius, height = 256 })

task.spawn(function()
	while radius > 10 do
		task.wait(10)
		radius -= 5
		-- Who is inside updates on the next tick.
		zone:reshape({ kind = "cylinder", base = center - vector.create(0, 64, 0), radius = radius, height = 256 })
		ui.actionBar(players.all(), `<red>The zone shrinks to {radius} blocks!`, 3)
	end
end)

task.spawn(function()
	while true do
		task.wait(1)
		for _, player in players.all() do
			if not zone:contains(player.position) then
				player:setHealth(math.max(player.health - 2, 0))
			end
		end
	end
end)