Apps Home
|
My Uploads
|
Create an App
Kate's Raffle
Author:
romeo_john
Description
Source Code
Launch App
Current Users
Created by:
Romeo_John
App Images
/* #################################################################################################### # # App: Kate's Raffle # Author: romeo_john # Version: 0.0.1 # Credits: _viper # #################################################################################################### */ var bg = "a1d451bf-81b7-4460-b911-8dd7ad5d0df0"; var font_size = 11; var font_weight = "bold"; var font_colour = "#000000"; var light_colour = '#F8D6E8'; var dark_colour = '#E9438A'; var panel_left_leftmargin = 15; var panel_right_leftmargin = 105; var FirstSetTicket = cb.settings.FirstSetTicket; var FirstSetCost = cb.settings.FirstSetCost; var SecondSetTicket = cb.settings.SecondSetTicket; var SecondSetCost = cb.settings.SecondSetCost; var ThirdSetTicket = cb.settings.ThirdSetTicket; var ThirdSetCost = cb.settings.ThirdSetCost; var FourthSetTicket = cb.settings.FourthSetTicket; var FourthSetCost = cb.settings.FourthSetCost; var NoticeMessage = cb.settings.NoticeMessage; var RoomName = cb.settings.RoomName; var DaysLeft = cb.settings.DaysLeft; var end = new Date(DaysLeft); var _second = 1000; var _minute = _second * 60; var _hour = _minute * 60; var _day = _hour * 24; var now = new Date(); var days = 0; var hours = 0; var minutes = 0; var seconds = 0; var timer; var FirstSet = new Boolean(); var SecondSet = new Boolean(); var ThirdSet = new Boolean(); var FourthSet = new Boolean(); var Notice = new Boolean(); var TipAmount = 0; var TempTipAmount = 0; var TicketAmount = 0; var TotalTickets = 0; var LastBuyer = "None"; var Tipper = null; var TicketCommand = "!tickets"; var ListCommand = "!list"; var UserTickets = {}; var langTokens = (cb.settings.tokens > 1) ? 'tokens' : 'token'; var numberOfSides = (cb.settings.die_type === 'Traditional') ? 6 : 10; 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'; cb.settings_choices = [{ name: 'DaysLeft', type: 'str', minLength: 0, required: true, defaultValue: "Aug 15, 2019 11:31 AM", label: "Raffle End Date" }, { name: 'FirstSetTicket', type: 'int', minValue: 1, default: 1, label: "(First Set) Ticket Amount" }, { name: 'FirstSetCost', type: 'int', minValue: 1, default: 100, label: "(First Set) Ticket Cost" }, { name: 'SecondSetTicket', type: 'int', minValue: 1, required: false, default: 5, label: "(Second Set) Ticket Amount" }, { name: 'SecondSetCost', type: 'int', minValue: 1, required: false, default: 300, label: "(Second Set) Ticket Cost" }, { name: 'ThirdSetTicket', type: 'int', minValue: 1, required: false, default: 10, label: "(Third Set) Ticket Amount" }, { name: 'ThirdSetCost', type: 'int', minValue: 1, required: false, default: 500, label: "(Third Set) Ticket Cost" }, { name: 'FourthSetTicket', type: 'int', minValue: 1, required: false, default: 20, label: "(Fourth Set) Ticket Amount" }, { name: 'FourthSetCost', type: 'int', minValue: 1, required: false, default: 1000, label: "(Fourth Set) Ticket Cost" }, { name: 'RoomName', type: 'str', minLength: 0, required: false, label: "Room Name" }, { name: 'NoticeMessage', type: 'str', minLength: 0, required: false, label: "Raffle Notice Message", defaultValue: ":octrafflecvf" }, { name: 'tokens', type: 'int', minValue: 1, maxValue: 100, label: 'How much do you want to charge per roll?', defaultValue: 25 }, { 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) die? (NOTE: If you choose the ' + 'Chinese die, please set all of the 21 prizes. Otherwise, just set the first 13.)', choice1: 'Traditional', choice2: 'Chinese', default: 'Traditional' }, { name: 'minimum_rolls', type: 'choice', label: 'What is the minimum number of rolls before the rare dice can appear? (Keep this a secret!)', choice1: 10, choice2: 15, choice3: 20, choice4: 25, choice5: 30, choice6: 35, choice7: 40, choice8: 45, choice9: 50, defaultValue: 10 }, { name: 'prize_1', type: 'str', label: 'Prize for rolling 1' }, { name: 'prize_2', type: 'str', label: 'Prize for rolling 2' }, { name: 'prize_3', type: 'str', label: 'Prize for rolling 3' }, { name: 'prize_4', type: 'str', label: 'Prize for rolling 4' }, { name: 'prize_5', type: 'str', label: 'Prize for rolling 5' }, { name: 'prize_6', type: 'str', label: 'Prize for rolling 6' }, { name: 'prize_7', type: 'str', label: 'Prize for rolling 7' }, { name: 'prize_8', type: 'str', label: 'Prize for rolling 8' }, { name: 'prize_9', type: 'str', label: 'Prize for rolling 9' }, { name: 'prize_10', type: 'str', label: 'Prize for rolling 10' }, { name: 'prize_11', type: 'str', label: 'Prize for rolling 11' }, { name: 'prize_12', type: 'str', label: 'Prize for rolling 12' }, { name: 'prize_13', type: 'str', default: 'A smile', label: 'Prize for rolling 13 (RARE if using traditional dice)' }, { name: 'prize_14', type: 'str', default: 'A smile', label: 'Prize for rolling 14 (only shown if using Chinese dice)' }, { name: 'prize_15', type: 'str', default: 'A smile', label: 'Prize for rolling 15 (only shown if using Chinese dice)' }, { name: 'prize_16', type: 'str', default: 'A smile', label: 'Prize for rolling 16 (only shown if using Chinese dice)' }, { name: 'prize_17', type: 'str', default: 'A smile', label: 'Prize for rolling 17 (only shown if using Chinese dice)' }, { name: 'prize_18', type: 'str', default: 'A smile', label: 'Prize for rolling 18 (only shown if using Chinese dice)' }, { name: 'prize_19', type: 'str', default: 'A smile', label: 'Prize for rolling 19 (only shown if using Chinese dice)' }, { name: 'prize_20', type: 'str', default: 'A smile', label: 'Prize for rolling 20 (only shown if using Chinese dice)' }, { name: 'prize_21', type: 'str', default: 'A smile', label: 'Prize for rolling 21 (RARE; only shown if using Chinese dice)' }]; cb.onTip(function(tip) { TipAmount = parseInt(tip['amount']); tipCounter += parseInt(tip['amount']); Tipper = tip['from_user']; TicketAmount = 0; TempTipAmount = 0; TempTipAmount = TipAmount; while (TempTipAmount >= cb.settings.FirstSetCost) { if (TempTipAmount === FirstSetCost) { TempTipAmount = TempTipAmount - FirstSetCost; TicketAmount = TicketAmount + FirstSetTicket; } if (TempTipAmount > FirstSetCost) { if (SecondSet && TempTipAmount < SecondSetCost) { TempTipAmount = TempTipAmount - FirstSetCost; TicketAmount = TicketAmount + FirstSetTicket; } else if (!SecondSet) { TempTipAmount = TempTipAmount - ThirdSetCost; TicketAmount = TicketAmount + ThirdSetTicket; } } if (TempTipAmount === SecondSetCost) { TempTipAmount = TempTipAmount - SecondSetCost; TicketAmount = TicketAmount + SecondSetTicket; } if (TempTipAmount > SecondSetCost) { if (ThirdSet && TempTipAmount < ThirdSetCost) { TempTipAmount = TempTipAmount - SecondSetCost; TicketAmount = TicketAmount + SecondSetTicket; } else if (!ThirdSet) { TempTipAmount = TempTipAmount - ThirdSetCost; TicketAmount = TicketAmount + ThirdSetTicket; } } if (TempTipAmount === ThirdSetCost) { TempTipAmount = TempTipAmount - ThirdSetCost; TicketAmount = TicketAmount + ThirdSetTicket; } if (TempTipAmount > ThirdSetCost) { if (FourthSet && TempTipAmount < FourthSetCost) { TempTipAmount = TempTipAmount - ThirdSetCost; TicketAmount = TicketAmount + ThirdSetTicket; } else if (!FourthSet) { TempTipAmount = TempTipAmount - ThirdSetCost; TicketAmount = TicketAmount + ThirdSetTicket; } } if (TempTipAmount >= FourthSetCost) { TempTipAmount = TempTipAmount - FourthSetCost; TicketAmount = TicketAmount + FourthSetTicket; } } if (TicketAmount === 1) { cb.sendNotice(Tipper + " has purchased " + TicketAmount + " ticket!", null, dark_colour, light_colour, "bold"); TotalTickets = TotalTickets + TicketAmount; LastBuyer = Tipper; TicketTracker(TicketAmount, Tipper); } else if (TicketAmount > 1) { cb.sendNotice(Tipper + " has purchased " + TicketAmount + " tickets!", null, dark_colour, light_colour, "bold"); TotalTickets = TotalTickets + TicketAmount; LastBuyer = Tipper; TicketTracker(TicketAmount, Tipper); } if (parseInt(tip['amount']) == cb.settings.tokens) { var numberOfRolls = Math.floor(parseInt(tip['amount']) / cb.settings.tokens); for (var i = 0; i < numberOfRolls; i++) { roll(tip['from_user']); lastRoller = tip['from_user']; } } else { cb.drawPanel(); } cb.drawPanel(); }); cb.onEnter(function(user) { if (Notice) { cb.sendNotice(NoticeMessage, user['user'], light_colour, dark_colour, "bold"); } }); cb.onMessage(function(msg) { var user = msg["user"]; if (msg["m"] === TicketCommand) { TicketPrices(); msg["X-Spam"] = true; } if (msg["m"] === ListCommand) { if (user === cb.room_slug || msg['is_mod']) { PrintList(); } else { PrintList(user); } msg["X-Spam"] = true; } 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']); } } }); cb.onDrawPanel(function (user) { return { "template": "image_template", "layers": [ {'type': 'image', 'fileID': bg}, { 'type': 'text', 'text': 'Tickets Sold: ', 'top': 5, 'left': panel_left_leftmargin, 'font-size': font_size, 'font-weight': font_weight, 'color': font_colour, }, { 'type': 'text', 'text': 'Last Buyer: ', 'top': 27, 'left': panel_left_leftmargin, 'font-size': font_size, 'font-weight': font_weight, 'color': font_colour, }, { 'type': 'text', 'text': 'Raffle Deadline: ', 'top': 51, 'left': panel_left_leftmargin, 'font-size': font_size, 'font-weight': font_weight, 'color': font_colour, }, { 'type': 'text', 'text': TotalTickets, 'top': 5, 'left': panel_right_leftmargin, 'font-size': font_size, 'font-weight': font_weight, 'color': font_colour, }, { 'type': 'text', 'text': LastBuyer, 'top': 27, 'left': panel_right_leftmargin, 'font-size': font_size, 'font-weight': font_weight, 'color': font_colour, }, { 'type': 'text', 'text': days + "d " + hours + "h " + minutes + "m " + seconds + "s remaining!", 'top': 51, 'left': panel_right_leftmargin, 'font-size': font_size, 'font-weight': font_weight, 'color': font_colour, } ], }; }); function init() { if (RoomName !== "") { cb.changeRoomSubject(RoomName); } cb.sendNotice("----------Ticket Prices---------", null, light_colour, dark_colour, "bold"); if (FirstSetTicket > 0 && FirstSetCost > 0) { if (FirstSetTicket === 1) { cb.sendNotice(FirstSetTicket + " ticket for " + FirstSetCost + " tokens", null, light_colour, dark_colour, "bold"); } else if (FirstSetTicket > 1) { cb.sendNotice(FirstSetTicket + " tickets for " + FirstSetCost + " tokens", null, light_colour, dark_colour, "bold"); } FirstSet = true; } else { FirstSet = false; } if (SecondSetTicket > 0 && SecondSetCost > 0) { cb.sendNotice(SecondSetTicket + " tickets for " + SecondSetCost + " tokens", null, light_colour, dark_colour, "bold"); SecondSet = true; } else { SecondSet = false; } if (ThirdSetTicket > 0 && ThirdSetCost > 0) { cb.sendNotice(ThirdSetTicket + " tickets for " + ThirdSetCost + " tokens", null, light_colour, dark_colour, "bold"); ThirdSet = true; } else { ThirdSet = false; } if (FourthSetTicket > 0 && FourthSetCost > 0) { cb.sendNotice(FourthSetTicket + " tickets for " + FourthSetCost + " tokens", null, light_colour, dark_colour, "bold"); FourthSet = true; } else { FourthSet = false; } cb.sendNotice("----------------------------------", null, light_colour, dark_colour, "bold"); if (NoticeMessage !== "") { Notice = true; cb.setTimeout(Advertise, 150000); } else { Notice = false; } setPrizes(); cb.setTimeout(showRemaining, 1000); } function Advertise() { if (Notice) { cb.sendNotice(NoticeMessage, null, light_colour, dark_colour, "bold"); cb.sendNotice("Tip " + cb.settings.tokens + " " + langTokens + " to roll the dice. \n Type \"!prizes\" to see the list of prizes. \nType \"!prizes all\" to send the list to all viewers if you're a mod or the broadcaster.\nType \"!winners\" to see a list of the last 20 winners.", null, light_colour, dark_colour, "bold"); cb.setTimeout(Advertise, 300000); } } function TicketPrices() { cb.sendNotice("----------Ticket Prices---------", null, light_colour, dark_colour, "bold"); if (FirstSet) { cb.sendNotice(FirstSetTicket + " tickets for " + FirstSetCost + " tokens", null, light_colour, dark_colour, "bold"); } if (SecondSet) { cb.sendNotice(SecondSetTicket + " tickets for " + SecondSetCost + " tokens", null, light_colour, dark_colour, "bold"); } if (ThirdSet) { cb.sendNotice(ThirdSetTicket + " tickets for " + ThirdSetCost + " tokens", null, light_colour, dark_colour, "bold"); } if (FourthSet) { cb.sendNotice(FourthSetTicket + " tickets for " + FourthSetCost + " tokens", null, light_colour, dark_colour, "bold"); } cb.sendNotice("----------------------------------", null, light_colour, dark_colour, "bold"); } function TicketTracker(amount, user) { if (amount <= 0) return; var before = UserTickets[user] || 0, after = UserTickets[user] = before + amount; } function sortList() { var TicketList = []; for (var user in UserTickets) { if (UserTickets.hasOwnProperty(user)) { TicketList.push(user, [UserTickets[user]]); } } return TicketList; } function PrintList(user = null) { var List = sortList(); var Name = []; var Tickets = []; if (List.length > 1) { cb.sendNotice("-------Ticket Purchases-------", user, light_colour, dark_colour, "bold"); for (a = 0; a < List.length; a = a + 2) { Name.push(List[a]); } for (b = 1; b < List.length; b = b + 2) { Tickets.push(List[b]); } for (c = 0; c < Name.length; c++) { if (Tickets[c] > 1) { cb.sendNotice(Name[c] + " bought " + Tickets[c] + " tickets", user, light_colour, dark_colour, "bold"); } else { cb.sendNotice(Name[c] + " bought " + Tickets[c] + " ticket", user, light_colour, dark_colour, "bold"); } } cb.sendNotice("----------------------------------", user, light_colour, dark_colour, "bold"); } else { cb.sendNotice("No tickets were purchased", user, light_colour, dark_colour, "bold"); } } function showRemaining() { var distance = end - now; days = Math.floor(distance / _day); hours = Math.floor((distance % _day) / _hour); minutes = Math.floor((distance % _hour) / _minute); seconds = Math.floor((distance % _minute) / _second); end = end - 1000; cb.drawPanel(); cb.setTimeout(showRemaining, 1000); } function roll(username) { rollCounter++; var die1 = Math.floor(Math.random() * numberOfSides + 1); var die2 = Math.floor(Math.random() * numberOfSides + 1); // convoluted logic to appease the dev gods on cb var randomNum = Math.ceil(Math.random() * (100 - minimumRollsToGetRareDice) + minimumRollsToGetRareDice); if (rollCounter === randomNum) { if ((die1 === 1) && (die2 !== 1)) die1 = (cb.settings.die_type === 'Traditional') ? 7 : 11; if ((die2 === 1) && (die1 !== 1)) die2 = (cb.settings.die_type === 'Traditional') ? 7 : 11; } var total = die1 + die2; var winner = false; if (total >= 1) { winner = true; var prize = cb.settings['prize_' + total]; } else { winner = false; var prize = 'A Thank You!'; } var prizeIndex = prizes.indexOf(prize); if (prizeIndex >= 0) { if (cb.settings.remove_winning_prize === 'Yes') prizes.splice(prizeIndex, 1); } else { prize = 'A Thank You!'; } var msg = dieImagePrefix + die1 + " " + dieImagePrefix + die2 + "\n"; msg += username + " rolled a " + total + "! \n".toUpperCase(); msg += "Roll #" + rollCounter + " | Prize: " + prize; var textColor = dark_colour; var bgColor = light_colour; if (winner) textColor = dark_colour; if (total === maxOutcome) { bgColor = light_colour; textColor = dark_colour; } cb.sendNotice(msg, '', bgColor, textColor, 'bold'); lastPrizeWon = prize; winners.push("Roll #" + rollCounter + " (" + total + "): " + username + " - " + prize); cb.drawPanel(); } function setPrizes() { var rareText = ''; for (var i = 1; i <= maxOutcome; i++) { if (i === maxOutcome) rareText = " (VERY RARE)"; prizes.push(cb.settings['prize_' + i] + rareText); } } function showPrizes(username) { if (prizes.length) { var rareText = ''; var msg = "##### POSSIBLE PRIZES #####"; for (var i = 1; i <= maxOutcome; i++) { if (i === maxOutcome) rareText = " (VERY RARE)"; if (prizes.indexOf(cb.settings['prize_' + i] + rareText) >= 0) msg += "\nRoll " + i + " - " + cb.settings['prize_' + i] + rareText; } } else { var msg = "SORRY! There are no prizes left in the list, but thank you for the tip. :thumbsup"; } cb.sendNotice(msg, username, light_colour, dark_colour, 'bold'); } function showPrizesWon(username) { var msg = "##### LAST 40 WINNERS #####"; msg += "\nList sorted in chronological order"; 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(-40); for (var i = 0; i < recentWinners.length; i++) msg += "\n" + recentWinners[i]; cb.sendNotice(msg, username, light_colour, dark_colour, 'bold'); } } init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.