Help me make a script for flipping a coin

can someone help me create a JavaScript for a coin flip. For the life of me i can’t figure it out. i would like for it to be a heads or tails however i would like it to be used with the wizebot currency. so for example if someone flip a coin they would put the amount they would like to flip and then if it lands on heads they win the amount they bet and if it lands on tails they lose that amount. In return the bot would display a message win or loose to let the viewers know how much currency they have left. (example !flip 50)

Hello,
Here is a script based on your request:

// Retrieve the user's name
let user_name = JS.datas('nick');

// Retrieve the amount bet by the user (provided as a command argument)
let betAmount = parseInt(JS.wizebot.command.args(1)); // Ensure the argument is a number

if (isNaN(betAmount) || betAmount <= 0) {
    JS.wizebot.send_chat_message("Please enter a valid amount to bet.");
    JS.utils.stop(); // Stop the script if the amount is not valid
}

// Check the user's current balance to ensure they have enough currency
let currentBalance = JS.wizebot.currency.get(user_name);

if (currentBalance < betAmount) {
    JS.wizebot.send_chat_message("Sorry " + user_name + ", you don't have enough currency to bet this amount.");
    JS.utils.stop(); // Stop the script if the user doesn't have enough currency
}

// Flip the coin
let flipResult = JS.utils.random(0, 1); // 0 for tails, 1 for heads

// Process the result
if (flipResult === 1) { // Win
    // Double the bet and add it to the user's balance
    JS.wizebot.currency.add(user_name, betAmount); // The winning is equal to the bet amount (so doubling the bet is achieved by adding the bet amount)
    JS.wizebot.send_chat_message("Congratulations " + user_name + ", the coin landed on heads! You win " + betAmount + ". Your new balance is " + (currentBalance + betAmount) + ".");
} else { // Lose
    // Subtract the bet from the user's balance
    JS.wizebot.currency.remove(user_name, betAmount);
    JS.wizebot.send_chat_message("Too bad " + user_name + ", the coin landed on tails. You lose " + betAmount + ". Your new balance is " + (currentBalance - betAmount) + ".");
}

This script was generated with ChatGPT, providing it with the basis for one of our scripts that uses virtual currency (and some other information from our documentation (Documentation - Wize.Bot)).

I give this indication, not to promote it, but to say that it’s possible for non-complex scripts to use it :slight_smile:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.