Apps Home
|
Create an App
A first test app
Author:
m_user4sex4fem
Description
Source Code
Launch App
Current Users
Created by:
M_User4sex4fem
(function() { var addTipper, bg, broadcaster, chatNotice, contains, convertMinutesToMs, endGame, endShow, fg, forceStopCount, isGameRunning, isShowRunning, newGame, randomTipper, sendNotice, startShow, startTimer, stopTimer, tippers, winner; cb.settings_choices = [ { name: 'time_limit', type: 'int', minValue: 0, maxValue: 60, "default": 5, label: 'How many minutes should the game last?' }, { name: 'tip_minimum', type: 'int', minValue: 0, maxValue: 1000, "default": 10, label: 'What is the minimum number of tokens to play?' }, { name: 'show_length', type: 'int', minValue: 0, maxValue: 60, "default": 3, label: 'How many minutes long is the show for the winner?' } ]; convertMinutesToMs = function(minutes) { return minutes * 60 * 1000; }; sendNotice = function(message) { return cb.sendNotice(message, broadcaster, bg, fg); }; chatNotice = function(message) { return cb.chatNotice(message, null, bg, fg); }; contains = function(collection, tipper) { var item, result, _i, _len; result = false; for (_i = 0, _len = collection.length; _i < _len; _i += 1) { item = collection[_i]; if (item === tipper) { result = true; } } return result; }; bg = '#556b2f'; fg = '#f5f5f5'; broadcaster = cb.room_slug; tippers = []; winner = ''; isGameRunning = false; isShowRunning = false; forceStopCount = 0; newGame = function() { if (isGameRunning || isShowRunning) { sendNotice('There is already a game in progress.'); return sendNotice("The following tippers are playing: \n" + (tippers.join(', ')) + "."); } else { chatNotice("Starting a new game of 'Spin the Bottle'! Tip " + cb.settings.tip_minimum + " token to join the game. After " + cb.settings.time_limit + " minutes a winner is randomly selected for a " + cb.settings.show_length + " minute show!"); return startTimer(); } }; endGame = function() { if (!isGameRunning && !isShowRunning) { sendNotice('There is no game in progress.'); sendNotice("Enter '/start' to begin a new game."); } else { if (isGameRunning) { if (forceStopCount < 1) { sendNotice("There is a game in progress with " + tippers.length + " players. Type '/stop' again to confirm ending this game early and resetting all players."); forceStopCount = forceStopCount + 1; } else { tippers.length = forceStopCount = 0; isGameRunning = false; chatNotice("" + broadcaster + " has ended the game early."); } } else if (isShowRunning) { if (forceStopCount < 1) { sendNotice("There is a winner's show in progress with " + winner + ". Type '/stop' to end the show immediately."); forceStopCount = forceStopCount + 1; } else { forceStopCount = 0; isShowRunning = false; cb.limitCam_stop(); chatNotice("" + broadcaster + " has ended the winner's show early."); } } } }; startTimer = function() { isGameRunning = true; return cb.setTimeout(function() { if (isGameRunning) { isGameRunning = false; if (tippers.length > 0) { return startShow(); } else { return chatNotice("Not enough tippers to play 'Spin the Bottle'"); } } }, convertMinutesToMs(cb.settings.time_limit)); }; stopTimer = function() { return isGameRunning = false; }; startShow = function() { isGameRunning = false; isShowRunning = true; winner = randomTipper(); chatNotice("" + winner + " wins 'Spin the Bottle' and gets a " + cb.settings.show_length + " minute show with " + broadcaster + "!"); cb.limitCam_start("'Spin the Bottle' show in progress.", [winner]); return cb.setTimeout(function() { return endShow(); }, convertMinutesToMs(cb.settings.show_length)); }; endShow = function() { cb.limitCam_stop(); isShowRunning = false; return chatNotice('The game has ended.'); }; addTipper = function(tipper) { if (!contains(tippers, tipper)) { chatNotice("" + tipper + " has joined the game!"); return tippers.push(tipper); } }; randomTipper = function() { var _atIndex; _atIndex = parseInt(Math.random() * tippers.length, 10); return winner = tippers[_atIndex]; }; cb.onTip(function(tip) { if (tip.amount >= cb.settings.tip_minimum) { return addTipper(tip.from_user); } }); cb.onMessage(function(message) { var _isBroadcaster, _isCommand; _isBroadcaster = broadcaster === message.user; _isCommand = (message.m.charAt(0)) === '/'; if (_isCommand && _isBroadcaster) { switch (message.m) { case '/start': message['X-Spam'] = true; return newGame(); case '/stop': message['X-Spam'] = true; return endGame(); } } }); }).call(this);
© Copyright Chaturbate 2011- 2026. All Rights Reserved.