COMMANDS
Your first command, in 18 lines.
Greet each player as they spawn, and add a /roll command that checks its input and announces the dice roll to everyone.
Write your first resourceconsole.log("hello is running");
Events.on("playerSpawned", (player) => {
Chat.sendToPlayer(player, `Hello, ${player.nickname}. Try /roll.`);
});
Events.on("playerCommand", (player, command, args) => {
if (command !== "roll") return;
const sides = Number(args[0] ?? 6);
if (!Number.isInteger(sides) || sides < 2 || sides > 1000) {
Chat.sendToPlayer(player, "Usage: /roll [sides], from 2 to 1000.");
return;
}
const result = 1 + Math.floor(Math.random() * sides);
Chat.sendToAll(`${player.nickname} rolls a d${sides}: ${result}`);
});