Type@ember/types
types.Region
A region of the world. Its entered and left signals fire as players cross its edge.
Signals
region.interacting: types.Intercept<types.InteractEvent>Runs before a player uses a map block inside the region; return false to stop it. Item use still happens.
Fields
region.alive: booleanFalse once the region has been removed.
region.name: stringThe region's name; several regions can share one.
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 }The text properties set on it in the editor or by world.regions.create.
Methods
region:contains(position: vector) -> booleanReturns whether a position is inside the region.
region:remove()Removes the region. Its signals stop and its players list empties.
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)