Apps Home
|
Create an App
Ryan's Multigoal Countdown
Author:
warppipe
Description
Source Code
Launch App
Current Users
Created by:
Warppipe
//vars for high and recent tippers var hightipper = '-'; var hightip = 0; var besttotaltipper = '-'; var besttotaltip = 0; var tiptotals = {} //goals and their amounts var goals = []; var goalamts = []; var tiptotal = 0; var currentgoal = 0; var goalcount = 0; var allgoalsreached = false; cb.settings_choices = [ {name: 'final_msg' , type: 'str', label: 'Final Message', required: true}, {name: 'tags' , type: 'str', label: 'Tags', required: false}, {name: 'goal1' , type: 'str', label: 'Goal', required: false}, {name: 'goal1amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal2' , type: 'str', label: 'Goal', required: false}, {name: 'goal2amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal3' , type: 'str', label: 'Goal', required: false}, {name: 'goal3amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal4' , type: 'str', label: 'Goal', required: false}, {name: 'goal4amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal5' , type: 'str', label: 'Goal', required: false}, {name: 'goal5amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal6' , type: 'str', label: 'Goal', required: false}, {name: 'goal6amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal7' , type: 'str', label: 'Goal', required: false}, {name: 'goal7amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal8' , type: 'str', label: 'Goal', required: false}, {name: 'goal8amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal9' , type: 'str', label: 'Goal', required: false}, {name: 'goal9amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal10' , type: 'str', label: 'Goal', required: false}, {name: 'goal10amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal11' , type: 'str', label: 'Goal', required: false}, {name: 'goal11amt' , type: 'int', label: 'Amount', required: false, minValue: 0}, {name: 'goal12' , type: 'str', label: 'Goal', required: false}, {name: 'goal12amt' , type: 'int', label: 'Amount', required: false, minValue: 0} ]; cb.onTip(function (tip) { //cumulativetips updatetiptotals(tip['from_user'], tip['amount']); //see if you're the high tipper if (tip['amount'] > hightip){ hightip = tip['amount']; hightipper = tip['from_user']; }; //if the goals are still running if (!allgoalsreached){ //add the tips to your tip total tiptotal += parseInt(tip['amount']) //see if you hit the goal goalcheck(); //set the room subject and draw the panel updateroom(); }; }); cb.onDrawPanel(function(user) { // i need to add a change for when you hit goal return { 'template': '3_rows_of_labels', 'row1_label': 'Tokens Remaining:', 'row1_value': parseInt(goalamts[currentgoal] - tiptotal), 'row2_label': 'Highest Tip:', 'row2_value': hightipper + ' (' + hightip + ')', 'row3_label': 'Best Total Tipper:', 'row3_value': besttotaltipper + ' (' + besttotaltip + ')' }; }); //look for changegoal, addtokens, and removetokens commands from the broadcaster cb.onMessage(function (msg) { //changegoal if(msg['m'].startsWith('/changegoal ') && msg['user'] == cb.room_slug){ goals[currentgoal] = msg['m'].substring(12); msg['X-Spam'] = true; updateroom(); }; //add if(msg['m'].startsWith('/add ') && msg['user'] == cb.room_slug){ tiptotal -= parseInt(msg['m'].substring(5)); msg['X-Spam'] = true; updateroom(); }; //sub if(msg['m'].startsWith('/sub ') && msg['user'] == cb.room_slug){ tiptotal += parseInt(msg['m'].substring(5)); goalcheck(); msg['X-Spam'] = true; updateroom(); }; //set if(msg['m'].startsWith('/set ') && msg['user'] == cb.room_slug){ tiptotal = 0 goalamts[currentgoal] = parseInt(msg['m'].substring(5)); goalcheck(); msg['X-Spam'] = true; updateroom(); }; //newgoal if(msg['m'].startsWith('/newgoal ') && msg['user'] == cb.room_slug){ var lastspaceindex = msg['m'].lastIndexOf(' ') //push goal goals.push(msg['m'].substring(9, lastspaceindex)); //push goal amount goalamts.push(parseInt(msg['m'].substring(lastspaceindex+1))); //add to goal total goalcount++ //make sure allgoals is off allgoalsreached = false msg['X-Spam'] = true; updateroom(); }; return msg; }); function init(){ var i for(i = 1; i <= 12; i++){ if (cb.settings['goal' + String(i) + 'amt'] != 0 && cb.settings['goal' + String(i) + 'amt'] != '' && cb.settings['goal' + String(i) + 'amt'] != null){ goals.push(cb.settings['goal' + String(i)]); goalamts.push(cb.settings['goal'+ String(i) + 'amt']); goalcount++; }; }; //set the room subject and draw the panel updateroom(); }; //function to check if a goal was hit function goalcheck(){ while (tiptotal >= goalamts[currentgoal]){ //set the tip total to the remainder tiptotal -= goalamts[currentgoal] //tell everyone we reached the goal cb.sendNotice('Goal Reached for ' + goals[currentgoal] + '!', '', '#FFFFFF', '#000000', 'bold'); //move to next goal currentgoal++; //see if that was the last goal if (currentgoal == goalcount){allgoalsreached = true; tiptotal=0;}; //stop counting tips, in case a new goal is added }; }; function updateroom(){ if (allgoalsreached==false){ cb.changeRoomSubject(goals[currentgoal] + ' [' + parseInt(goalamts[currentgoal] - tiptotal) +' tokens remaining] ' + cb.settings.tags); } else { cb.changeRoomSubject(cb.settings.final_msg + ' ' + cb.settings.tags); }; cb.drawPanel(); }; function updatetiptotals(user, tip){ if (user in tiptotals){ tiptotals[user] += tip } else { tiptotals[user] = tip }; for (const i in tiptotals){ if (tiptotals[i] > besttotaltip){ besttotaltipper = i besttotaltip = tiptotals[i] }; }; cb.sendNotice(tiptotals, '') }; init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.