Type@ember/commands
commands.CommandOptions
What a command takes and does.
Fields
commandOptions.args: { commands.CommandArg }?its arguments, in the order they are typed
commandOptions.description: string?a line saying what it does
commandOptions.dev: boolean?makes it usable only in development deployments and by the deployment's admins
local commands = require("@ember/commands")
local world = require("@ember/world")
-- A testing shortcut: `dev = true` hides the command except in development deployments and for
-- the deployment's admins, so it is safe to leave in.
commands.register("tospawn", {
description = "Teleport to the spawn point",
dev = true,
run = function(player)
player:teleport(world.spawn, world.spawnLook)
end,
})runs with the player and the arguments by name; it may yield, and an error tells the player the command failed
local commands = require("@ember/commands")
local world = require("@ember/world")
-- `run` is a task of its own, so it can wait. An error inside it tells the player "That command
-- failed." and reports the error to the creator console.
commands.register("warp", {
description = "Warp to the lobby after a short warm-up",
run = function(player)
local start = player.position
for seconds = 3, 1, -1 do
player:send(`<yellow>Teleporting in {seconds}... don't move.`)
task.wait(1)
-- They may have left while we waited.
if not player.alive then
return
end
if vector.magnitude(player.position - start) > 1 then
player:send("<red>You moved; teleport cancelled.")
return
end
end
player:teleport(world.markers.single("lobby").position)
end,
})