Apps Home
|
Create an App
7 Minutes in Heaven
Author:
rascal8484
Description
Source Code
Launch App
Current Users
Created by:
Rascal8484
// Spin the Bottle // --------------- // // Model sets the minimum tip amount, the time frame for tipping (in minutes), and length of the show for the winner // (in minutes). // // Users tip the minimum amount during the time frame, and once the time frame ends, a random tipper is selected for // a special (one-on-one) show with the model. var spin; cb.settings_choices = [ { name: 'time_limit', type: 'int', minValue: 1, maxValue: 60, default: 5, label: "How long to wait before choosing a winner (in minutes)?" }, { name: 'tip_minimum', type: 'int', minValue: 1, maxValue: 10000, default: 10, label: "What is the minimum tip amount to join the circle?" }, { name: 'show_length', type: 'int', minValue: 1, maxValue: 60, default: 3, label: "How long of a show does the winner get (in minutes)?" } ]; // Handlers // -------- cb.onTip(function(tip) { if (tip.amount >= cb.settings.tip_minimum) { spin.addTipper(tip.from_user); } else { cb.log("tip from", tip.from_user, "is not big enough for 'Spin the Bottle':", tip.amount); } }); cb.onMessage(function (msg) { if (cb.room_slug === msg['user'] && msg['m'] === '/start') { msg['X-Spam'] = true; if(!spin.isRunning()) { spin.start() } else { if (cb.sendNotice) { cb.sendNotice("'Spin the Bottle' has already started! The following users have already joined the circle:" + spin.tippers(), cb.room_slug); } } } if (cb.room_slug === msg['user'] && msg['m'] === '/stop') { msg['X-Spam'] = true; if(spin.isRunning()) { spin.stop() } else { if (cb.sendNotice) { cb.sendNotice("'Spin the Bottle' was not running...", cb.room_slug); } } } }); // Initialization // -------------- function init() { spin = (function() { var timer; var tippers = []; var running = false; function getTipper(user) { var tipper = []; for (var i = 0; i < tippers.length; i++) { if (tippers[i] === user) { tipper.push(user); } } return tipper.length >= 1; } function setTipper(user) { tippers.push(user); } function convertToMs(minutes) { return minutes * 60 * 1000; }; function getRandomTipper() { return tippers[parseInt(Math.random() * tippers.length, 10)]; }; function startShow(winner) { cb.chatNotice(cb.room_slug + ' spun the bottle and it ended up facing ' + winner + '! Starting a ' + cb.settings.show_length + ' minute show now!'); cb.limitCam_start("'Spin the Bottle' show in progress.", [winner]); cb.setTimeout(function() { cb.chatNotice("This game of 'Spin the Bottle' is over... shall we play again?"); cb.limitCam_stop() }, convertToMs(cb.settings.show_length)); }; function startTimer() { running = true; timer = cb.setTimeout(function() { if (running) { running = false; if (tippers.length > 0) { startShow(getRandomTipper()); tippers.length = 0; } else { cb.chatNotice('There were no tippers... guess nobody wants to play.'); } } }, convertToMs(cb.settings.time_limit)); }; function stopTimer() { running = false; tippers = []; }; // Return public API return { start: function() { if (!running) { cb.chatNotice('Spin the Bottle has started!'); cb.chatNotice('Join the circle by tipping at least ' + cb.settings.tip_minimum + ' tokens. After ' + cb.settings.time_limit + ' minute' + (cb.settings.time_limit === 1 ? '' : 's') + ' the bottle gets spun and the winner gets a ' + cb.settings.show_length + ' minute one-on-one show with the model!'); startTimer() } }, stop: function() { if (running) { cb.chatNotice('The model has stopped the game. Nobody is a winner. :sadface:'); stopTimer(); } }, addTipper: function(user) { if (running && !getTipper(user)) { cb.chatNotice(user + ' has been added to the circle!'); setTipper(user); } }, isRunning: function() { return running; }, tippers: function() { return tippers.join(', '); } } })(); }; init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.