Bots Home
|
Create an App
Tip Hunter
Author:
notthatfrank
Description
Source Code
Launch Bot
Current Users
Created by:
Notthatfrank
var curr_tips = []; var curr_target; var curr_round = 0; var tok_min = Math.min(cb.settings.tokens_min, cb.settings.tokens_max); var tok_max = Math.max(cb.settings.tokens_min, cb.settings.tokens_max); var play_mode = 0; var txt_ever = 'ever'; var txt_minutes = 'a given number of minutes'; var txt_rounds = 'a number of rounds'; var bot_running = true; var time_delta = 0; var remain_secs = cb.settings.play_count*60; var plays = new Object; var wins = new Object; var background = "#FFFFFF"; var foreground = "#0629AC"; //var foreground = "#FFFFFF"; //var background = "#0629AC"; // bot options cb.settings_choices = [ {name: 'prize', type: 'str', minLength: 1, maxLength: 255, label: 'Game Prize'}, {name: 'tokens_min', type: 'int', minValue: 1, default: 1, label: 'Min. Tokens to Play'}, {name: 'tokens_max', type: 'int', minValue: 1, default: 10, label: 'Max. Tokens to Play'}, {name: 'play_mode', type: 'choice', label: 'Play for...', choice1: txt_ever, choice2: txt_minutes, choice3: txt_rounds, defaultValue: txt_minutes}, {name: 'play_count', type: 'int', minValue: 1, default: 5, label: 'Minutes/Rounds'}, ]; function resetTips() { for (i=tok_min; i<=tok_max; i++) { curr_tips[i-tok_min] = false; } curr_target = randomInt(tok_min, tok_max); } function sortedLeaders() { var winners = Object.keys(wins); winners.sort(function(a, b){return wins[b]-wins[a]}); return winners; } function displayLeaders(user, maxwinners) { var winners = sortedLeaders(); var response = "Leaders: "; if (undefined == user) { user = ''; } if (undefined == maxwinners) { maxwinners = Math.min(5, winners.length); } else if (0 == maxwinners) { maxwinners = winners.length; } if (0 == winners.length) { response += "None yet :o("; } else { for (i=0; i<maxwinners; i++) { response += "\n" + winners[i] + ": " + wins[winners[i]] + " win(s)"; } } if (maxwinners < winners.length) { response += "\nType '!thleaders' for entire leaderboard."; } cb.sendNotice(response, user, background, foreground); } function displayTips(user) { var response = 'Remaining tips this round: ['; if (undefined == user) { user = ''; } if (!bot_running) { cb.sendNotice("Tip Hunter game has ended", user, background, foreground); return; } for (i=0; i<curr_tips.length; i++) { if (curr_tips[i]) { response += 'x '; } else { response += (i+tok_min).toString() + ' '; } } response += '] '; cb.sendNotice(response, user, background, foreground); if (cb.room_slug == user) { // the broadcaster gets to know what the secret no. is cb.sendNotice('Secret number this round: ' + curr_target.toString(), cb.room_slug, background, foreground); } } function randomInt(min,max) { return Math.floor(Math.random()*(max-min+1)+min); } cb.onTip(function (tip) { var amount = parseInt(tip['amount']); var user = tip['from_user']; if (!bot_running) { return; } if (amount >= tok_min && amount <= tok_max) { if (undefined == plays[user]) { plays[user] = 0; wins[user] = 0; } plays[user]++; if (!curr_tips[amount-tok_min]) { curr_tips[amount-tok_min] = true; if (amount == curr_target) { cb.sendNotice("Congratulations " + user + "! " + tip['amount'] + " was this round's secret number!", '', background, foreground); wins[user]++; cb.sendNotice(user + " has now won " + wins[user] + " time(s)", '', background, foreground); newRound(); } else { cb.sendNotice("Sorry " + user + ", " + tip['amount'] + " was not the secret number!", user, background, foreground); } } } }); function newRound() { if (2 == play_mode && bot_running) { // playing for x rounds bot_running = (curr_round < cb.settings.play_count); if (!bot_running) { endGame(); } }; if (bot_running) { curr_round++; resetTips(); cb.sendNotice("Tip Hunter round " + curr_round.toString() + (2 == play_mode ? (" of " + cb.settings.play_count.toString()) : '') + " started! Tip between " + tok_min + " and " + tok_max + " to play. Type '!tiphunt' for status." + "\nGame prize: " + cb.settings.prize, '', background, foreground); } } function endGame() { var winner = sortedLeaders(); cb.sendNotice("Tip Hunter: Game has ended!", '', background, foreground, 'bold'); if (winner.length > 0) { var wintext = ":3star Contratulations"; var i = 0; var winners = 0; while (wins[winner[i]] == wins[winner[0]]) { wintext += " " + winner[i]; winners++; i++; } if (winners > 1) { wintext += " (" + winners.toString() + "-way tie)"; } cb.sendNotice(wintext + ", you've WON Tip Hunter! :o)", '', background, foreground, 'bold'); } displayLeaders(undefined, 0); } function prettyTime(secs) { var mins = Math.floor(secs/60); secs = secs % 60; return mins.toString() + ':' + (secs < 10 ? '0' : '') + secs.toString(); } function updateTime() { // we're just running on rough estimates here remain_secs -= time_delta; if (remain_secs <= 30) { // less than 30 secs left time_delta = 5; // 5 secs } else if (remain_secs <= 180) { // less than three minutes left time_delta = 20; // 20 secs } else if (remain_secs <= 6000) { // less than 10 minutes left time_delta = 60; // one minute } else { time_delta = 5*60; // five minutes } if (remain_secs > 0) { cb.sendNotice("Tip Hunter: " + prettyTime(remain_secs) + " remaining.", '', background, foreground); if (curr_tips.length > 0) { displayTips(); } cb.setTimeout(updateTime, time_delta*1000); } else { endGame(); bot_running = false; } } function updateStatus() { if (bot_running) { cb.sendNotice("Tip Hunter is running. Tip between " + tok_min + " and " + tok_max + " to play. " + "Type '!tiphunt' for status.", '', background, foreground); displayTips(); cb.setTimeout(updateStatus, 3*60*1000); // every three minutes } } cb.onMessage(function (m) { if ('!tiphunt' == m['m'] || '!tiphunter' == m['m']) { // other users don't need to see this message m['X-Spam'] = true; displayTips(m['user']); displayLeaders(m['user']); } else if ('!thleaders' == m['m']) { // display entire leaderboard to this user displayLeaders(m['user'], 0); } }); if (cb.settings.play_mode == txt_ever) { play_mode = 0; cb.setTimeout(updateStatus, 3*60*1000); // stats every three minutes } else if (cb.settings.play_mode == txt_minutes) { play_mode = 1; updateTime(); } else if (cb.settings.play_mode == txt_rounds) { play_mode = 2; cb.setTimeout(updateStatus, 3*60*1000); // stats every three minutes } newRound();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.