Chat commands
A chat command is a function that runs when a player types /name or !name.
modkit.commands.add("heal", function(player)
if not player.hasDino then player:message("Spawn first.") return end
player:setHealth(player.maxHealth)
player:setHunger(player.maxHunger)
player:setThirst(player.maxThirst)
player:message("Healed.")
end, true)
The third argument true makes it admin only. Other players get the answer admin only.
Where commands come from
- A chat message that starts with
/or!. - The game's own chat command call (
ServerExecuteChatCommand). The plugin listens to both and runs a command only once when the same line arrives twice within 1.5 seconds. - The F8 console of a launcher client. The console is off by default,
ISLEMODKIT_CONSOLE=1in the environment of the game turns it on.
Arguments
The line is split at spaces. The handler receives the player and then every word as a string.
modkit.commands.add("tp", function(player, x, y, z)
x, y, z = tonumber(x), tonumber(y), tonumber(z)
if not (x and y and z) then player:message("usage: /tp x y z") return end
player:teleport(x, y, z)
end, true)
There is no quoting. /say hello world gives two arguments. Join them again if you need the full text.
modkit.commands.add("say", function(player, ...)
modkit.chat.broadcast(table.concat({ ... }, " "), player.name)
end)
Rules
- Register names in lower case. The typed command is lowered before the lookup, a command registered as
"Heal"is never found. - Every resource has its own command table. If two resources register the same name, the resource that is loaded first wins.
- A line that matches a command is not shown in the chat. A line that matches no command goes on to the game untouched, so the game's own commands keep working.
- The
chatCommandevent fires for every command line, also for unknown ones. It gets the player and the line without the leading/.
Answering
| Call | Player sees it | Works without launcher |
|---|---|---|
player:message(text [, sender]) |
as a chat line | yes |
player:notify(text) |
as a game notification | yes |
player:announce(text [, title [, seconds]]) |
as a big announcement | yes |
player:print(text) |
in the F8 console | no |
Reference: commands natives, chat natives.