Bots Home
|
Create an App
Roll The Dice Test 1
Author:
beautyanthedick
Description
Source Code
Launch Bot
Current Users
Created by:
Beautyanthedick
/** * Dice Roller by BeautyanTheDick * Version: 1.0 * Author: BeautyanTheDick * Date: 8/15/2018 * Loosely based on work by: kingchris_, zingknaat, milo_bloom, tablesalt90, aety */ cb.settings_choices = [ {name: 'settings_section_label', type:'choice', label:'------ Basic Settings ------', required: false}, { name: 'themebg', type: 'str', label: 'Background Color', defaultValue: '#ffe0f6'}, { name: 'themefg', type: 'str', label: 'Foreground Color', defaultValue: '#d11010'}, { name: 'tokens', type: 'int', minValue: 1, label: 'Tip amount per roll?', defaultValue: 11 }, { name: 'notice_wait_time', type: 'int', label: 'How long in minutes to Advertise Rolls?', defaultValue: 1 }, { name: 'change_room_subject', type: 'choice', label: 'Change Room Subject?', choice1: 'Yes', choice2: 'No', defaultValue: 'No' }, {name: 'multirolls_subsection_label', type:'choice', label:'------ Multi Rolls ------', required: false}, { name: 'max_rolls_at_once', type: 'choice', label: 'Maximum number of rolls per tip?', choice1: '1', choice2: '2', choice3: '3', choice4: '4', choice5: '5', choice6: '6', choice7: '7', choice8: '8', choice9: '9', defaultValue: 9 }, { name: 'perfect_multi', type: 'choice', label: 'Require exact multiple to roll?', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, {name: 'prizeodds_subsection_label', type:'choice', label:'------ Prize Odds ------', required: false}, { name: 'equal_odds', type: 'choice', label: 'Non-Rare prizes have equal odds of being rolled? ("no" simulates rolling a pair of dice and "yes" rolls a single die)', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, { name: 'last_prize_rare', type: 'choice', label: 'Should the last prize in the list be RARE? (RARE prizes will only show up after a minimum number of rolls have been rolled and should be significantly less likely than other prizes)', choice1: 'Yes', choice2: 'No', defaultValue: 'No' }, { name: 'minimum_rolls', type: 'int', minValue: 0, label: 'Minimum number of rolls before rare occurs.', defaultValue: 9 }, { name: 'rare_chance_mult', type: 'choice', //[TODO] Remove in favor of multiplier with precalced odds 1/2, 1, 2 etc 1x should be 1/2 odds for equal die? label: 'Multiplier for the chance of rolling rare prizes. Increase if rare prizes are too uncommon, Decrease if they\'re too common', choice1: '1/2x', choice2: '1x', choice3: '1.5x', choice4: '2x', choice5: '4x', choice6: '8x', defaultValue: '1x' }, { name: 'prize_section_label', type:'choice', label:'------ Prizes ------', required: false}, { name: 'prize_1', type: 'str', label: 'Prize 1', defaultValue: 'Flash Tits'}, { name: 'prize_2', type: 'str', label: 'Prize 2', defaultValue: 'Flash Ass'}, { name: 'prize_3', type: 'str', label: 'Prize 3', defaultValue: 'Flash Dick or Pussy'}, { name: 'prize_4', type: 'str', label: 'Prize 4', defaultValue: 'Flash Feet'}, { name: 'prize_5', type: 'str', label: 'Prize 5', defaultValue: 'Blow Job or Suck Dildo'}, { name: 'prize_6', type: 'str', label: 'Prize 6', defaultValue: 'Lick Boobies'}, { name: 'prize_7', type: 'str', label: 'Prize 7', defaultValue: 'Spank w/ Hand'}, { name: 'prize_8', type: 'str', label: 'Prize 8', defaultValue: 'Spank w/ Paddle'}, { name: 'prize_9', type: 'str', label: 'Prize 9', defaultValue: 'Spank Belly'}, { name: 'prize_10', type: 'str', label: 'Prize 10', defaultValue: 'Spank Dick or Pussy'}, { name: 'prize_11', type: 'str', label: 'Prize 11', defaultValue: 'Nipple Fight'}, { name: 'prize_12', type: 'str', label: 'Prize 12', defaultValue: 'Finger Pussy or Jerkoff'}, ]; var maxPrizes = 12; for(var i=13; i <= maxPrizes; i++) { cb.settings_choices.push({ name: 'prize_' + i, type: 'str', label: 'Prize ' + i, required: false }); } cb.settings_choices.push({name: 'miscellaneous_section_label', type:'choice', label:'------ Advanced Settings (Safe to Ignore) ------#', required: false}); cb.settings_choices.push({name: 'cmd_prefix', type: 'str', minLength: 1, maxLength: 1, label: 'Prefix for bot commands. (Might want to change if you have other bots using the same commands.)', defaultValue: '/'}); cb.settings_choices.push({name: 'die_prefix', type: 'str', label: 'Prefix for die gifs ("prefix#" only change if you know what you\'re doing)', defaultValue: ':80genericdie_'}); var rollprice = parseInt(cb.settings.tokens); var prizeCount = 13; var equalOdds = cb.settings.equal_odds == 'yes'; var numberOfDie = equalOdds?1:2; var die = [ { die: 1, label: "One", sides: Math.floor((equalOdds? ((cb.settings.last_prize_rare == 'yes')?prizeCount-1:prizeCount) : ((cb.settings.last_prize_rare == 'yes')?prizeCount:prizeCount+1)/2)) }, { die: 2, label: "Two", sides: Math.ceil((equalOdds? ((cb.settings.last_prize_rare == 'yes')?prizeCount-1:prizeCount) : ((cb.settings.last_prize_rare == 'yes')?prizeCount:prizeCount+1)/2)) } ]; var themebg = cb.settings.themebg; var themefg = cb.settings.themefg; var perfectMults = cb.settings.perfect_multi == 'yes'; var maxRollsPerTip = parseInt(cb.settings.max_rolls_at_once); var usingRares = cb.settings.last_prize_rare == 'yes'; var minRollsForRare = parseInt(cb.settings.minimum_rolls); var rareChance = (cb.settings.rare_chance_mult == '1x')?1:((cb.settings.rare_chance_mult == '1/2x')?0.5:((cb.settings.rare_chance_mult == '1.5x')?1.5:(cb.settings.rare_chance_mult == '2x')?2:(cb.settings.rare_chance_mult == '4x')?4:8)); var changeSubject = cb.settings.change_room_subject == 'Yes'; var cmdPrefix = cb.settings.cmd_prefix; var diePrefix = cb.settings.die_prefix; var lastRoller = '--'; var lastPrizeWon = '--'; var prizes = []; var stats = { 'tipCounter': 0, 'winners': [], 'rollCounter': 0, 'rollResultCounts': {}, }; cb.onTip(function(tip) { var tipAmount = parseInt(tip.amount); stats.tipCounter += tipAmount; if(tipAmount >= rollprice && (!perfectMults || ((tipAmount <= (maxRollsPerTip*rollprice)) && (tipAmount % rollprice === 0)))) { var rolls = Math.floor(tipAmount/rollprice); for(var i = 0; i < rolls; i++) { roll(tip.from_user); lastRoller = tip.from_user; } } else { //not rolling the dice var textColor = '#000000'; var bgColor = '#D9FAD7'; 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': stats.tipCounter + ' ' + ((stats.tipCounter > 1)?'tokens':'token') + ' received / rolled ' + stats.rollCounter + ' time(s)' }; }); cb.onEnter(function (user) { adBlurb(user.user); }); cb.onMessage(function(msg) { var message = msg.m.split(" "); switch (message[0]) { case cmdPrefix+'dicehelp': msg["X-Spam"] = true; // Don't print command messages to chat. msg.background = "#EEEEEE"; if(message[1] == 'all' && isPrivileged(msg))adBlurb(); else adBlurb(msg.user); break; case cmdPrefix+'winners': msg["X-Spam"] = true; msg.background = "#EEEEEE"; if(message[1] == 'all' && isPrivileged(msg))winnersBlurb(); else winnersBlurb(msg.user); break; case cmdPrefix+'prizes': msg["X-Spam"] = true; msg.background = "#EEEEEE"; if(message[1] == 'all' && isPrivileged(msg))prizesBlurb(); else prizesBlurb(msg.user); break; case cmdPrefix+'dicestats': msg["X-Spam"] = true; msg.background = "#EEEEEE"; if(message[1] == 'all' && isPrivileged(msg))statsBlurb(); else statsBlurb(msg.user); break; default: break; } return msg; }); function getRandomIntInclusive(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; } function isPrivileged(msg) { return (msg.is_mod === true) || (msg.user == cb.room_slug); } function roll(username) { var prize = 'A Thank You!'; stats.rollCounter += 1; var dieResults = []; var total = -numberOfDie; for(var i = 0; i < numberOfDie; i++) { dieResults[i] = getRandomIntInclusive(1, die[i].sides); total += dieResults[i]; } if(usingRares && (stats.rollCounter > minRollsForRare) && (getRandomIntInclusive(1, 100) <= (rareChance/100))) { //RARE PRIZE WON!!! if(numberOfDie == 1) { dieResults[0] = die[0].sides+1; total = dieResults[0] - numberOfDie; } else { if(getRandomIntInclusive(0,1) === 0) { dieResults[0] = die[0].sides+1; dieResults[1] = die[1].sides; total = dieResults[0] + dieResults[1] - numberOfDie; } else { dieResults[0] = die[0].sides; dieResults[1] = die[1].sides+1; total = dieResults[0] + dieResults[1] - numberOfDie; } } } var winner = false; if (total >= 0 && total < prizeCount) { if((total+numberOfDie) in stats.rollResultCounts)stats.rollResultCounts[(total+numberOfDie)] += 1; else stats.rollResultCounts[(total+numberOfDie)] = 1; winner = true; prize = prizes[total]; } else { winner = false; } var msg = ((numberOfDie == 1)?diePrefix + dieResults[0]: diePrefix + dieResults[0] + " " + diePrefix + dieResults[1]) + "\n"; msg += username + " rolled " + (total+numberOfDie) + "! \n".toUpperCase(); msg += "Roll #" + stats.rollCounter + " | Prize: " + prize; var textColor = '#000000'; var bgColor = '#D9FAD7'; if (winner) textColor = '#067D00'; if (total == prizeCount-1) { bgColor = '#FFDBF3'; textColor = '#A805A6'; } cb.sendNotice(msg, '', bgColor, textColor, 'bold'); lastPrizeWon = prize; stats.winners.push("Roll #" + stats.rollCounter + " (" + (total+numberOfDie) + "): " + username + " - " + prize); if(stats.winners.length > 20)stats.winners = stats.winners.slice(-21); cb.drawPanel(); } function initPrizes() { for (var i = 1; i <= maxPrizes; i++) { if(!('prize_' + i in cb.settings) || cb.settings['prize_' + i] === '' || cb.settings['prize_' + i] == '.' || cb.settings['prize_' + i] == ' ')continue; if(i%2 == 1)prizes.push(cb.settings['prize_' + i]); else prizes.unshift(cb.settings['prize_' + i]); } prizeCount = prizes.length; if(usingRares) { if(prizeCount%2 === 0)prizes.push(prizes.shift()); prizes[prizes.length-1] += " (RARE)"; } for(var i = 0; i < prizeCount; i++) { stats.rollResultCounts[(i+numberOfDie)] = 0; } die[0].sides = Math.floor(((numberOfDie == 1)? ((cb.settings.last_prize_rare == 'yes')?prizeCount-1:prizeCount) : ((cb.settings.last_prize_rare == 'yes')?prizeCount:prizeCount+1)/2)); die[1].sides = Math.ceil(((numberOfDie == 1)? ((cb.settings.last_prize_rare == 'yes')?prizeCount-1:prizeCount) : ((cb.settings.last_prize_rare == 'yes')?prizeCount:prizeCount+1)/2)); rareChance *= equalOdds?100/(prizeCount*1.3):100/((die[0].sides+1)*die[1].sides); cb.log(rareChance); } function statsBlurb(username) { var msg = "~*~ Dice Roll Statistics ~*~\n"; for(var rollval in stats.rollResultCounts) { msg += "Roll " + rollval + ": " + stats.rollResultCounts[rollval] + "\n"; } msg += "Total Rolls: " + stats.rollCounter; cb.sendNotice(msg, username, themebg, themefg, 'bold'); } function prizesBlurb(username) { var msg = "No Prizes!! D:"; if (prizes.length) { msg = "~*~ POSSIBLE PRIZES ~*~"; for (var i = 0; i < prizeCount; i++) { msg += "\nRoll " + (i+numberOfDie) + " - " + prizes[i]; } } cb.sendNotice(msg, username, themebg, themefg, 'bold'); } function winnersBlurb(username) { var msg = "~*~ LAST 20 WINNERS ~*~"; msg += "\nList sorted in chronological order"; if (stats.winners.length === 0) { cb.sendNotice('No one has won anything yet. Roll the dice to win a prize!', username, '', '', 'bold'); } else { var recentWinners = stats.winners.slice(-21); for (var i = 0; i < recentWinners.length; i++) msg += "\n" + recentWinners[i]; cb.sendNotice(msg, username, themebg, themefg, 'bold'); } } function adBlurb(username) { var msg = ""; msg += "~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~\n\n"; msg += "Dice Roller by BeautyanTheDick - Tip " + rollprice + " " + ((rollprice>1)?'tokens':'token') + " To Roll\n"; msg += "Prizes Include ("+ prizes +")\n\n"; msg += "Prizes - 1. "+ cb.settings.prize_1 +" \u2605 "; msg += "2. "+ cb.settings.prize_2 +" \u2605 "; msg += "3. "+ cb.settings.prize_3 +" \u2605 "; msg += "4. "+ cb.settings.prize_4 +" \u2605 "; msg += "5. "+ cb.settings.prize_5 +" \u2605 "; msg += "6. "+ cb.settings.prize_6 +" \u2605 "; msg += "7. "+ cb.settings.prize_7 +" \u2605 "; msg += "8. "+ cb.settings.prize_8 +" \u2605 "; msg += "9. "+ cb.settings.prize_9 +" \u2605 "; msg += "10. "+ cb.settings.prize_10 +" \u2605 "; msg += "11. "+ cb.settings.prize_11 +" \u2605 "; msg += "12. "+ cb.settings.prize_12 +" \u2605 \n"; msg += "~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~"; cb.sendNotice(msg, username, themebg, themefg, 'bold'); } function advertise() { adBlurb(); if(cb.settings.notice_wait_time > 0)cb.setTimeout(advertise, parseInt(cb.settings.notice_wait_time) * 60000); } function init() { initPrizes(); advertise(); if (changeSubject) { cb.changeRoomSubject('Tip ' + rollprice + ' ' + ((rollprice>1)?'tokens':'token') + ' to roll the dice and win a prize!'); } } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.