Bots Home
|
Create an App
09g Roll the Dice
Author:
09g
Description
Source Code
Launch Bot
Current Users
Created by:
09g
/** * Roll the Dice: Improved * Version: 1.1.1 * Author: kingchris_ * Date: 2021-01-28 * Additional Contributors: aety, zingknaat, milo_bloom, tablesalt90 */ cb.settings_choices = [ { name: 'tokens', type: 'int', minValue: 1, label: 'How much do you want to charge per roll?', defaultValue: 33 }, { name: 'remove_winning_prize', type: 'choice', label: 'Remove prize from list after each roll?', choice1: 'Yes', choice2: 'No', defaultValue: 'No' }, { name: 'die_type', type: 'choice', label: 'Use Traditional (6-sided) or Chinese (10-sided) dice? (NOTE: If you choose Chinese, please set all prizes. Otherwise, just set 2-13)', choice1: 'Traditional', choice2: 'Chinese', defaultValue: 'Traditional' }, { name: 'multirolls', type: 'int', minValue: 1, label: 'What is the maximum number of rolls you want a user to be able to make in a single tip? (set to 1 to disable) Example: If you set this to 3 and you charge 33 tokens per roll, a user could tip 66 for 2 rolls or 99 for 3 rolls. Any other tip amounts will be ignored.', defaultValue: 3 }, { name: 'minimum_rolls', type: 'choice', label: 'Minimum number of rolls before the rare dice can appear?', choice1: 10, choice2: 15, choice3: 20, choice4: 25, choice5: 30, choice6: 35, choice7: 40, choice8: 45, choice9: 50, defaultValue: 20 }, { name: 'rarechance', type: 'int', minValue: 1, maxValue: 100, label: 'Percent chance for a rare die roll (7 for traditional dice, 11 for Chinese dice) to occur once minimum rolls has been reached. Default: 10%.', defaultValue: 10 }, { name: 'notice_wait_time', type: 'choice', label: 'In minutes, how often should the app advertise itself?', choice1: 5, choice2: 10, choice3: 15, choice4: 20, choice5: 25, choice6: 30, choice7: 45, choice8: 60, defaultValue: 10 }, { name: 'change_room_subject', type: 'choice', label: 'Change room subject when using this bot?', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, {name: 'prize_2', type: 'str', label: 'Prize for rolling 2', defaultValue: 'dance'}, {name: 'prize_3', type: 'str', label: 'Prize for rolling 3', defaultValue: 'flash boobs'}, {name: 'prize_4', type: 'str', label: 'Prize for rolling 4', defaultValue: 'flash pussy'}, {name: 'prize_5', type: 'str', label: 'Prize for rolling 5', defaultValue: 'flash butt'}, {name: 'prize_6', type: 'str', label: 'Prize for rolling 6', defaultValue: 'flash (you choose what)'}, {name: 'prize_7', type: 'str', label: 'Prize for rolling 7', defaultValue: 'suck nipples'}, {name: 'prize_8', type: 'str', label: 'Prize for rolling 8', defaultValue: 'pussy close up'}, {name: 'prize_9', type: 'str', label: 'Prize for rolling 9', defaultValue: 'camel toe'}, {name: 'prize_10', type: 'str', label: 'Prize for rolling 10', defaultValue: 'spank butt'}, {name: 'prize_11', type: 'str', label: 'Prize for rolling 11', defaultValue: 'spank butt both hands'}, {name: 'prize_12', type: 'str', label: 'Prize for rolling 12', defaultValue: 'spank pussy'}, {name: 'prize_13', type: 'str', label: 'Prize for rolling 13 (RARE if using traditional dice)', defaultValue: 'finger pussy 10 mins'}, {name: 'prize_14', type: 'str', label: 'Prize for rolling 14 (only shown if using Chinese dice)', defaultValue: '.'}, {name: 'prize_15', type: 'str', label: 'Prize for rolling 15 (only shown if using Chinese dice)', defaultValue: '.'}, {name: 'prize_16', type: 'str', label: 'Prize for rolling 16 (only shown if using Chinese dice)', defaultValue: '.'}, {name: 'prize_17', type: 'str', label: 'Prize for rolling 17 (only shown if using Chinese dice)', defaultValue: '.'}, {name: 'prize_18', type: 'str', label: 'Prize for rolling 18 (only shown if using Chinese dice)', defaultValue: '.'}, {name: 'prize_19', type: 'str', label: 'Prize for rolling 19 (only shown if using Chinese dice)', defaultValue: '.'}, {name: 'prize_20', type: 'str', label: 'Prize for rolling 20 (only shown if using Chinese dice)', defaultValue: '.'}, {name: 'prize_21', type: 'str', label: 'Prize for rolling 21 (RARE if using Chinese dice)', defaultValue: '.'} ]; var price = cb.settings.tokens; var langTokens = (price > 1) ? 'tokens' : 'token'; var numberOfSides = (cb.settings.die_type == 'Traditional') ? 6 : 10; var multiRolls = cb.settings.multirolls; var lastRoller = '--'; var lastPrizeWon = '--'; var rollCounter = 0; var tipCounter = 0; var winners = []; var prizes = []; var minimumRollsToGetRareDice = parseInt(cb.settings.minimum_rolls); var maxOutcome = (cb.settings.die_type == 'Traditional') ? 13 : 21; var dieImagePrefix = (cb.settings.die_type == 'Traditional') ? ':reddie___' : ':cdie'; var rareChance = parseInt(cb.settings.rarechance); // percent chance of rolling a RARE (minimum rolls must also be met) cb.onTip(function (tip) { var maxTip = multiRolls * price; var tipAmount = parseInt(tip['amount']); // check to see if tip was for a dice roll if (tipAmount >= price && (tipAmount <= maxTip) && (tipAmount % price === 0)) { var numberOfRolls = Math.floor(tipAmount / price); for (var i = 0; i < numberOfRolls; i++) { roll(tip['from_user']); lastRoller = tip['from_user']; } } else { // Tip was for something else, don't roll the dice var textColor = '#000000'; var bgColor = '#D9FAD7'; //cb.sendNotice('Tip was not for dice roll.', '', bgColor, textColor, 'bold'); //tipCounter += parseInt(tip['amount']); cb.drawPanel(); } }); cb.onDrawPanel(function (user) { return { 'template': '3_rows_12_22_31', 'row1_label': 'Last prize won:', 'row1_value': lastPrizeWon, 'row2_label': 'Last player:', 'row2_value': lastRoller, 'row3_value': tipCounter + ' ' + langTokens + ' received / rolled ' + rollCounter + ' time(s)' }; }); cb.onEnter(function (user) { showAppAd(user['user']); }); cb.onMessage(function (msg) { if (msg['m'].match(/!winners/i)) { msg['X-Spam'] = true; showPrizesWon(msg['user']); } else if (msg['m'].match(/!prizes/i)) { msg['X-Spam'] = true; if (msg['m'].match(/all/i) && ((msg['is_mod'] === true) || (msg['user'] == cb.room_slug))) { showPrizes(); } else { showPrizes(msg['user']); } } return msg; }); // https://stackoverflow.com/a/1527820 function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; } function roll(username) { var prize = 'A Thank You!'; rollCounter++; var die1 = getRandomInt(1, numberOfSides); var die2 = getRandomInt(1, numberOfSides); // see if there's a chance we can roll a rare die if (rollCounter > minimumRollsToGetRareDice) { if (getRandomInt(0, 100) <= rareChance) { if (Math.random() <= 0.5) die1 = numberOfSides + 1; else die2 = numberOfSides + 1; } } var total = die1 + die2; var winner = false; if (total >= 1) { winner = true; prize = cb.settings['prize_' + total]; } else { winner = false; } var prizeIndex = (total == maxOutcome) ? prizes.indexOf(prize+' (RARE)') : prizes.indexOf(prize); if (prizeIndex >= 0) { if (cb.settings.remove_winning_prize == 'Yes') prizes.splice(prizeIndex, 1); } else { prize = 'A Thank You!'; } var strPrize = (total == maxOutcome) ? 'RARE PRIZE' : 'Prize'; var dieImage1 = dieImagePrefix + die1; var dieImage2 = dieImagePrefix + die2; // 7th die image is missing from the :reddie_ emoticon set so use the the old :reddie set if (cb.settings.die_type == 'Traditional') { if (die1 == 7) dieImage1 = ":reddie7"; else if (die2 == 7) dieImage2 = ":reddie7"; } var msg = dieImage1 + " " + dieImage2 + "\n"; msg += username + " rolled " + total + "! \n"; msg += "Roll #" + rollCounter + " | " + strPrize + ": " + prize; var textColor = '#000000'; var bgColor = '#D9FAD7'; if (winner) textColor = '#067D00'; if (total == maxOutcome) { bgColor = '#FFDBF3'; textColor = '#A805A6'; } cb.sendNotice(msg, '', bgColor, textColor, 'bold'); lastPrizeWon = prize; prize = (total == maxOutcome) ? "(RARE) " + prize : prize; winners.push("Roll #" + rollCounter + " (" + total + "): " + username + " - " + prize); cb.drawPanel(); } function setPrizes() { var rareText = ''; for (var i = 2; i <= maxOutcome; i++) { if (i == maxOutcome) rareText = "(RARE) "; prizes.push(cb.settings['prize_' + i] + rareText); } } function showPrizes(username) { var msg = "SORRY! There are no prizes left in the list, but thank you for the tip. :thumbsup"; if (prizes.length) { var rareText = ''; msg = "\n\u2666\u2666\u2666\u2666\u2666\u2666 ROLL THE DICE - POSSIBLE PRIZES \u2666\u2666\u2666\u2666\u2666\u2666\n\n"; for (var i = 2; i <= maxOutcome; i++) { if (i == maxOutcome) rareText = "(RARE) "; if (prizes.indexOf(cb.settings['prize_' + i] + rareText) >= 0) msg += "Roll " + i + " - " + rareText + cb.settings['prize_' + i] + "\n"; } } cb.sendNotice(msg, username, '#222222', '#50e1f4', 'bold'); } function showPrizesWon(username) { var msg = "\n\u2666\u2666\u2666\u2666\u2666\u2666 ROLL THE DICE - LAST 20 WINNERS \u2666\u2666\u2666\u2666\u2666\u2666\n\n"; msg += "List sorted in chronological order\n"; if (winners.length === 0) { cb.sendNotice('No one has won anything yet. Roll the dice to win a prize!', username, '', '', 'bold'); } else { var recentWinners = winners.slice(-20); for (var i = 0; i < recentWinners.length; i++) msg += recentWinners[i] + "\n"; cb.sendNotice(msg, username, '#FFF0DE', '#8A4900', 'bold'); } } function advertise() { showAppAd(); cb.setTimeout(advertise, parseInt(cb.settings.notice_wait_time) * 60000); } function showAppAd(username) { var msg = "********************************************\n"; msg += "We are playing Roll the Dice: Improved v1.1.1\n"; msg += "by kingchris_ (with contributions from: aety, zingknaat, milo_bloom, tablesalt90)\n"; msg += "********************************************\n"; msg += "\u2666 There are " + prizes.length + " possible prizes. "; if (cb.settings.remove_winning_prize == 'Yes') { msg += "Each prize won will be removed from the list.\n"; } else { msg += "Each prize won will stay on the list.\n"; } msg += "\n\u2666 Tip " + price + " " + langTokens + " to roll the dice. \n"; if (multiRolls > 1) msg += "\u2666 You can roll a maximum of " + multiRolls + " times in a single tip (" + (multiRolls*price) + " tokens). \n\n"; msg += "\u2666 Type \"!prizes\" to see the list of prizes. \n"; msg += "\u2666 Type \"!prizes all\" to send the list to all viewers if you're a mod or the broadcaster.\n"; msg += "\u2666 Type \"!winners\" to see a list of the last 20 winners.\n"; msg += "********************************************"; cb.sendNotice(msg, username, '#fff799', '#107888', 'bold'); } function init() { setPrizes(); advertise(); if (cb.settings.change_room_subject == 'Yes') { cb.changeRoomSubject('Tip ' + price + ' ' + langTokens + ' to roll the dice and win a prize!'); } } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.