Apps Home
|
Create an App
keep it hyped
Author:
test01
Description
Source Code
Launch App
Current Users
Created by:
Test01
/********************************************************************************* Author: CuzI'mFappy Title: Keep It Hyped Description: varient of Keep It Going by ACOOLA; introduces multiple thresholds and overtime, plus bonuses for the highest tippers and mods. Change Log: v1.0 - 2016-02-20: Initial Release. **********************************************************************************/ var isItGoing = 0; var isOvertime = 0; var goalMet = 0; var tipJar = 0; var totalTip = 0; var showOrNot = ""; var roomName = cb.settings.room_name; var startApp = new Date(); var startAt = cb.settings.get_it_going; //var lastTipper = ''; var reduceTJ = cb.settings.reduce_tip_jar * 1000; var reduceBy = cb.settings.reduce_tips_by; var subsequentStartAt = cb.settings.subsequent_tip_threshold; var overtime =cb.settings.tip_jar_overtime; var resumeShow = reduceBy; var bigTipper = "--"; var firstGoalMet = 0; var bigTip = 0; var bigTipLocation = -1; var overtimeLeft =0; var topTipper = new Array(); var ttLength = 0; var modFactor=10; cb.changeRoomSubject(roomName + ' [Start Tipping]'); cb.setTimeout(checkJar, reduceTJ); cb.chatNotice("Type '/stats' to see statistics."); cb.chatNotice("Broadcasters and Mods: Type '/help' to see additional functions."); var COMMAND_SHOW_LEADERBOARD = '!lb', CONFIG_COLOR_LEADER = '#9f9', NL = '\n', user_total_tips = {}, user_last_tip = {}, user_max_tip = {}, user_weighted_total = {}, leader_username = null; function handleTip(amount, user) { user_total_tips[user] = (user_total_tips[user] || 0) + amount; user_max_tip[user] = (user_max_tip[user] || 0) < amount ? user_max_tip[user] : amount; user_weighted_total[user] = (user_weighted_total[user] || 0)+ parseInt(parseInt(amount) * parseInt(findFactor(user))); user_last_tip[user] = amount; } function reduceLeaders(){ for (var i in user_weighted_total){ if(user_weighted_total[i] > user_total_tips[i]) user_weighted_total[i]--; } } function sortLeaderboard(){ var lb = new Array(); for (user in user_total_tips) { lb.push([user_weighted_total[user], user_total_tips[user], user_last_tip[user], user ]); } if (lb.length > 0){ lb.sort(function(a,b){ return (parseInt(a)==parseInt(b)) ? 0 : (parseInt(a)<parseInt(b) ? 1 : -1); }); leader_username = lb[0][3]; } return lb; } function formatRanking(leaderboard, rank){ if (rank < leaderboard.length) { var p = leaderboard[rank]; return p[3] + ' (' + p[1] + ' tokens)'; } else { return '--'; } } function drawLeaderboard() { var lb = sortLeaderboard(), out = 'Token leaderboard' + NL, rank; out += '---------------------------' + NL; if (lb.length == 0) { out += 'No tips yet...' } else { for (rank=0; rank<=lb.length; rank+=1) { out += '' + (rank+1) +'. ' + formatRanking(lb, rank) + NL; } } cb.chatNotice(out); } function checkJar() { var now= Date.now()/1000; //cb.log("isOvertime:" + isOvertime); //cb.log("overtimeLeft:" + overtimeLeft); if(isItGoing == 1) { if(tipJar>0) { tipJar=tipJar-reduceBy; } else { cb.log("beginning Overtime") beginOvertime(); } }else if (isOvertime==1) { if (overtimeLeft>0){ overtimeLeft = overtimeLeft-(reduceTJ/1000); } else{ endOvertime(); } } cb.setTimeout(checkJar, reduceTJ); cb.drawPanel(); } function beginOvertime(){ isOvertime=1; isItGoing=0; overtimeLeft=overtime; } function endOvertime(){ isOvertime=0; startAt=subsequentStartAt; goalMet = 0; tipJar=0; resetApp(); } function checkTip(u,t) { var exists = 0; var location = 0; for (i=0;i<topTipper.length;i++){ if(topTipper[i].username == u) { exists = 1; location = i; } } if (exists == 1) { topTipper[location].amount += t; } else { var tipper=new Object(); tipper.username=u; tipper.amount=t; topTipper[ttLength] = tipper; ttLength++; } for (i=0;i<topTipper.length;i++){ if(topTipper[i].amount > bigTip) { bigTip = topTipper[i].amount; bigTipLocation = i; } } bigTipper = topTipper[bigTipLocation].username + "(" + topTipper[bigTipLocation].amount + ")"; } function printTokens(x) { cb.chatNotice("*** Keep It Going - Tokens Earned by User ***",x); for (i=0;i<topTipper.length;i++) { cb.chatNotice(topTipper[i].username + " (" + topTipper[i].amount + ")",x); } cb.chatNotice("Total Tips: " + totalTip,x); } function resetApp() { tipJar = 0; isItGoing = 0; cb.changeRoomSubject(roomName + " - [Tip to start the show!]"); } function chageTimer(x) { if (x == 'Faster') { if (reduceTJ > 1000) { reduceTJ -= 1000; } } else if (x=='Slower') { if (reduceTJ < 60000) { reduceTJ += 1000; } } else if (x=='Fastest') { reduceTJ = 1000; } else if (x=='Slowest') { reduceTJ = 60000; } else if (x=='Pause') { reduceBy=0; } else if (x=='Resume') { reduceBy=resumeShow; } } function printHelp(x) { var help = "*** Keep It Going App - Help ***\n"; help += "If 'Show Is On' is in the Keep It Going Status, start your show\n"; help += "If 'STOP SHOW!!' is in the Keep It Going Status, stop your show\n"; help += "You can control how quickly the Tip Jar empties:\n"; help += "Type '/faster' to speed up emptying the Tip Jar\n"; help += "Type '/slower' to slow down emptying the Tip Jar\n"; help += "Type '/fastest' to set emptying Tip Jar Rate to 1 sec\n"; help += "Type '/slowest' to set emptying Tip Jar Rate to 60 secs\n"; help += "Type '/resume' to resume Tip Jar emptying\n"; help += "Type '/pause' to pause Tip Jar emptying\n"; help += "Type '/tokens' to see the amount each tipper has tipped."; cb.chatNotice(help, x); } function findFactor(tip){ /* cb.log(sortLeaderboard()); var leaders=sortLeaderboard(); var TipperRank =leaders.length; for (var i in leaders){ if(leaders[i][3]==tip['from_user']){ TipperRank=parseInt(i)+1; } } cb.log(tip['from_user'] +" is currently ranked #"+TipperRank); */ var factor=1; // if(parseInt(TipperRank)==1) factor=2; // if(parseInt(TipperRank)==2) factor=1.5; // if(parseInt(TipperRank)==3) factor=1.3; if (tip['from_user_tipped_recently'])factor=1.25; if (tip['from_user_tipped_alot_recently'])factor=1.5; if (tip['from_user_tipped_tons_recently'])factor=2; if (tip['from_user_in_fanclub'])factor=5; if (tip['from_user_is_mod'])factor=modFactor; return factor } function printStats(x) { var running = ((new Date()).getTime() - startApp.getTime()) / 1000; var minutes = Math.round(running/60); var hours = Math.floor(minutes/60); minutes = minutes%60; var runningStr = hours + ' hrs. ' + minutes + ' mins.'; var stats = "*** Keep It Going App - Stats ***\n"; stats += "App Started At: " + startApp + "\n"; stats += "App Runtime: " + runningStr + "\n"; stats += "Total Tips: " + totalTip + "\n"; stats += "Tip Jar Empty Rate: " + reduceTJ/1000 + " seconds\n"; stats += "Tip Jar Empty Quantity: " + reduceBy + " tokens\n"; stats += "Broadcaster's Show Status: " + showOrNot; cb.chatNotice(stats,x); } //Chaturbate API calls cb.settings_choices = [ {name:'room_name', type: 'str', minLength: 1, maxLength: 255, label:'Room subject:'}, {name:'get_it_going', type:'int', minValue:1, default:50, label:'Tips needed to start 1st show:'}, {name:'reduce_tip_jar', type:'int', minValue:1, maxValue:60, default:1, label:'Reduce the tip jar every X seconds:'}, {name:'reduce_tips_by', type:'int', minValue:1, maxValue:20, default:1, label:'Amount to reduce tip jar by:'}, {name:'tip_jar_overtime', type:'int', minValue:1, default:30, label:'Number of seconds in Overtime:'}, {name:'subsequent_tip_threshold', type:'int', minValue:1, default:75, label:'Tips needeed for subsequent shows:'}, ]; cb.onDrawPanel(function(user) { if (user == cb.room_slug) { if (isItGoing == 1) { showOrNot = "THE SHOW IS ON!"; } else { showOrNot = "STOP! STOP! STOP!"; } return { 'template': '3_rows_of_labels', 'row1_label':'Keep It Going:', 'row1_value':showOrNot, 'row2_label':'Total Tokens Earned:', 'row2_value':"" + totalTip + ' Tokens', 'row3_label': 'Tip Jar:', 'row3_value': tipJar }; } else { if(isItGoing == 1) { return { 'template': '3_rows_of_labels', 'row1_label': 'Keep It Going:', 'row1_value': 'Don\'t Let It Empty', 'row2_label': 'Tip Jar:', 'row2_value': tipJar, 'row3_label': 'Big Tipper:', 'row3_value': bigTipper }; } else if (isItGoing == 0 && goalMet == 1 && isOvertime == 1) { var toGo = startAt - tipJar; return { 'template': '3_rows_of_labels', 'row1_label': 'OVERTIME!', 'row1_value': overtimeLeft +" seconds to keep it going!", 'row2_label': 'Tip Jar:', 'row2_value': tipJar, 'row3_label': 'Big Tipper:', 'row3_value': bigTipper }; } else if (isItGoing == 0 && goalMet == 1 && isOvertime == 0) { var toGo = startAt - tipJar; return { 'template': '3_rows_of_labels', 'row1_label': 'Lets Get It Going!', 'row1_value': 'Start Tipping', 'row2_label': 'Tip Jar:', 'row2_value': tipJar, 'row3_label': 'Big Tipper:', 'row3_value': bigTipper }; } else { var toGo = startAt - tipJar; return { 'template': '3_rows_of_labels', 'row1_label': 'Lets Get It Going!', 'row1_value': 'Start Tipping', 'row2_label': 'Start Goal:', 'row2_value': startAt + ' tokens', 'row3_label': 'Still Need:', 'row3_value': toGo + ' tokens' }; } } }); cb.onTip(function (tip) { handleTip(tip.amount, tip.from_user); var factor=findFactor(tip); tipJar += parseInt(tip['amount']*factor) totalTip += parseInt(tip['amount']) //lastTipper = tip['from_user'] if(isItGoing == 0 && goalMet ==0) { if(tipJar >= startAt) { isItGoing = 1; goalMet = 1; firstGoalMet=1; cb.changeRoomSubject(roomName + ' - [Keep it Going!]'); } } else if (isItGoing == 0 && goalMet == 1){ isItGoing = 1; goalMet = 1; cb.changeRoomSubject(roomName + ' - [Keep It Going!]'); } checkTip(tip['from_user'],tip['amount']); var leaders=sortLeaderboard(); var TipperRank =leaders.length; for (var i in leaders){ if(leaders[i][3]==user){ TipperRank=parseInt(i)+1; } } //if (TipperRank <=3){ // cb.chatNotice("You are in #"+TipperRank+" place, your next tip will be multiplied by "+factor,tip.from_user,'#fff','#008','bold'); // } cb.drawPanel(); }); cb.onMessage(function (msg) { if (msg['m'] == '/faster' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; chageTimer("Faster"); } else if (msg['m'] == '/fastest' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; chageTimer("Fastest"); } else if (msg['m'] == '/slower' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; chageTimer("Slower"); } else if (msg['m'] == '/slowest' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; chageTimer("Slowest"); } else if (msg['m'] == '/pause' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; chageTimer("Pause"); } else if (msg['m'] == '/resume' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; chageTimer("Resume"); } else if (msg['m'] == '/help' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; printHelp(msg['user']); } else if (msg['m'] == '/factor2' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; modFactor=2; } else if (msg['m'] == '/factor5' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; modFactor=5; } else if (msg['m'] == '/factor10' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; modFactor=10; } else if (msg['m'].substr(0,5) == '/name' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; roomName = msg['m'].substr(6); } else if (msg['m'].substr(0,4) == '/ban' && (msg['user'] == cb.room_slug || msg['is_mod'])) { msg['X-Spam'] = true; cb.limitCam_removeUsers([msg['m'].substr(5)]); } else if (msg['m'] == '/stats') { msg['X-Spam'] = true; printStats(msg['user']); } else if (msg['m'] == '/limit') { msg['X-Spam'] = true; cb.limitCam_start("Your ability to view the show has been removed\n Please enhance your calm.",cb.limitCam_allUsersWithAccess()); } else if (msg['m'] == '/tokens') { msg['X-Spam'] = true; printTokens(msg['user']); } else if (msg['user'] == "cuzimfappy" ) { msg['background'] = '#bbdd33'; } else if (bigTipLocation >= 0) { if (msg['user'] == topTipper[bigTipLocation].username) { msg['background'] = '#ccff00'; } } else if (msg['m'] == '/leader') { msg['X-Spam'] = true; drawLeaderboard(); } return msg; }); cb.onEnter(function(user) { var help = "*** Keep It Hyped ***\n"; help += "The better tip jar!:\n"; help += "The hit the tip jar\'s threshold to start the show.\n"; help += "Tip during overtime to keep the action going!\n"; help += "Tips from fan club members count 5x as much!\n"; help += "dark blue = 1.25X, purple=1.5X, dark purple=2X!\n"; help += "With great power, comes great irresponsibility."; cb.chatNotice(help, user['user']); cb.limitCam_addUsers([user['user']]); });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.