From 0f7cb474a30e41f2718f11f45500d09c07631b5e Mon Sep 17 00:00:00 2001 From: NouSixXD Date: Tue, 15 Oct 2024 02:36:12 +0200 Subject: [PATCH] /diceroll command (#1748) --- Games/core/Player.js | 42 +++++++++++++++++++++++++ react_main/src/constants/commandList.js | 4 +++ 2 files changed, 46 insertions(+) diff --git a/Games/core/Player.js b/Games/core/Player.js index fc88f4584..d46dde390 100644 --- a/Games/core/Player.js +++ b/Games/core/Player.js @@ -419,6 +419,48 @@ module.exports = class Player { return; } } + return; + case "diceroll": + + if (this.dicerollCooldown == true) { + this.sendAlert(`This command has a 5 seconds cooldown, wait plz`); + return; + } + this.dicerollCooldown = true + setTimeout(() => { + this.dicerollCooldown = false + }, 5000); + + let amountOfRolls = 1 + let diceType = 6; + + if (cmd.args.length == 1) { + amountOfRolls = cmd.args[0]; + } else if (cmd.args.length >= 2) { + amountOfRolls = cmd.args[0]; + diceType = cmd.args[1]; + } + + if (amountOfRolls > 10) { + amountOfRolls = 10; + } + + let rollsOutput = `${this.name} rolled d` + diceType + ` dice ` + amountOfRolls + ` times and got `; + + for (let i = 0; i < amountOfRolls; i++) { + + let roll = Math.floor(Math.random() * diceType) + 1; + + if (i === amountOfRolls - 1) { + rollsOutput += roll + '.'; + } else { + rollsOutput += roll + ', '; + } + + } + + this.game.sendAlert(rollsOutput); + return; } diff --git a/react_main/src/constants/commandList.js b/react_main/src/constants/commandList.js index 6fb9febec..d5f784d7e 100644 --- a/react_main/src/constants/commandList.js +++ b/react_main/src/constants/commandList.js @@ -24,4 +24,8 @@ export const commandList = { input: "Role name", description: "Used to display role descriptions in chat.", }, + "/diceroll": { + input: "Amount, Dice Type", + description: "Rolls dice, results are shown to everyone.", + }, };