Apps Home
|
Create an App
TestRoulette
Author:
katie_prize
Description
Source Code
Launch App
Current Users
Created by:
Katie_Prize
// ============================================ // Title: Token Roulette // Description: A roulette game where tippers spin the wheel by sending tokens // Version: 1.0 // ============================================ // ============================================ // STATE VARIABLES // ============================================ var totalTipped = 0; var highTipUsername = null; var highTipAmount = 0; var lastTipUsername = null; var lastTipAmount = 0; var subjectIsSetWithZero = false; var prizes = []; var currentPrize = null; var spinHistory = []; // ============================================ // SETTINGS CONFIGURATION // ============================================ cb.settings_choices = [ // Goal settings { name: 'token_goal', type: 'int', minValue: 1, maxValue: 99999, defaultValue: 500, label: 'Token Goal for Main Prize' }, // Spin settings { name: 'spin_cost', type: 'int', minValue: 1, maxValue: 1000, defaultValue: 25, label: 'Tokens to Spin the Wheel' }, // Description { name: 'goal_description', type: 'str', minLength: 1, maxLength: 255, defaultValue: '🎰 Spin the Roulette!', label: 'Room Subject Description' }, // Prize options { name: 'prize_1', type: 'str', minLength: 1, maxLength: 255, defaultValue: '💋 Blow a Kiss', label: 'Prize 1 (Required)' }, { name: 'prize_2', type: 'str', minLength: 1, maxLength: 255, defaultValue: '👀 Flash (5 sec)', label: 'Prize 2 (Required)' }, { name: 'prize_3', type: 'str', minLength: 1, maxLength: 255, required: false, label: 'Prize 3 (Optional)' }, { name: 'prize_4', type: 'str', minLength: 1, maxLength: 255, required: false, label: 'Prize 4 (Optional)' }, { name: 'prize_5', type: 'str', minLength: 1, maxLength: 255, required: false, label: 'Prize 5 (Optional)' }, { name: 'prize_6', type: 'str', minLength: 1, maxLength: 255, required: false, label: 'Prize 6 (Optional)' }, { name: 'prize_7', type: 'str', minLength: 1, maxLength: 255, required: false, label: 'Prize 7 (Optional)' }, { name: 'prize_8', type: 'str', minLength: 1, maxLength: 255, required: false, label: 'Prize 8 (Optional)' }, // Notification settings { name: 'show_spin_animation', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', label: 'Show Spin Animation in Chat' }, { name: 'announce_color', type: 'str', maxLength: 7, defaultValue: '#FF69B4', label: 'Announcement Background Color (hex)' } ]; // ============================================ // EVENT HANDLERS // ============================================ /** * Handle incoming tips */ cb.onTip(function (tip) { var amount = parseInt(tip.amount); // Update totals totalTipped += amount; if (totalTipped > cb.settings.token_goal) { totalTipped = cb.settings.token_goal; } // Track tip stats lastTipAmount = amount; lastTipUsername = tip.from_user; if (amount > highTipAmount) { highTipAmount = amount; highTipUsername = tip.from_user; } // Check if this is a spin if (amount === cb.settings.spin_cost) { spinTheWheel(tip.from_user); } else if (amount >= cb.settings.spin_cost) { // Multiple spins for tips that are multiples of spin cost var numSpins = Math.floor(amount / cb.settings.spin_cost); for (var i = 0; i < numSpins; i++) { spinTheWheel(tip.from_user); } } // Update UI updateSubject(); cb.drawPanel(); return tip; }); /** * Draw the info panel */ cb.onDrawPanel(function (user) { var remaining = tipsRemaining(); var progress = Math.round((totalTipped / cb.settings.token_goal) * 100); return { 'template': '3_rows_of_labels', 'row1_label': 'Progress:', 'row1_value': totalTipped + ' / ' + cb.settings.token_goal + ' (' + progress + '%)', 'row2_label': 'Current Prize:', 'row2_value': currentPrize || 'Spin to reveal!', 'row3_label': 'Spin Cost:', 'row3_value': cb.settings.spin_cost + ' tokens' }; }); /** * Handle chat messages for commands */ cb.onMessage(function (msg) { var message = msg.m.toLowerCase(); // /prizes - Show all possible prizes if (message.match(/^\/prizes$/i)) { msg['X-Spam'] = true; if (msg.is_mod || msg.user === cb.room_slug) { showPrizes(); // Show to everyone } else { showPrizesToUser(msg.user); } } // /prizes all - Mods/broadcaster can show prizes to everyone if (message.match(/^\/prizes\s+all$/i)) { msg['X-Spam'] = true; if (msg.is_mod || msg.user === cb.room_slug) { showPrizes(); } else { cb.sendNotice('Only mods and broadcaster can use /prizes all', msg.user); } } // /spin - Show spin info if (message.match(/^\/spin$/i)) { msg['X-Spam'] = true; cb.sendNotice( '🎰 ROULETTE INFO 🎰\n' + '• Tip ' + cb.settings.spin_cost + ' tokens to spin the wheel!\n' + '• ' + prizes.length + ' possible prizes await!\n' + '• Type /prizes to see all possible prizes', msg.user ); } // /reset - Broadcaster only command to reset progress if (message.match(/^\/reset$/i)) { msg['X-Spam'] = true; if (msg.user === cb.room_slug) { totalTipped = 0; highTipAmount = 0; highTipUsername = null; spinHistory = []; updateSubject(); cb.drawPanel(); cb.sendNotice('🔄 Roulette has been reset!'); } else { cb.sendNotice('Only the broadcaster can reset the roulette.', msg.user); } } // /history - Show recent spin history if (message.match(/^\/history$/i)) { msg['X-Spam'] = true; showSpinHistory(msg.user); } // /stats - Show statistics if (message.match(/^\/stats$/i)) { msg['X-Spam'] = true; showStats(msg.user); } // /help - Show available commands if (message.match(/^\/help$/i) || message.match(/^\/roulette$/i)) { msg['X-Spam'] = true; showHelp(msg.user); } return msg; }); /** * Welcome users when they enter */ cb.onEnter(function (user) { if (user.has_tokens) { cb.sendNotice( '🎰 Welcome ' + user.user + '! Spin the Roulette for ' + cb.settings.spin_cost + ' tokens!\n' + 'Type /prizes to see what you can win!', user.user ); } }); // ============================================ // CORE FUNCTIONS // ============================================ /** * Spin the roulette wheel */ function spinTheWheel(username) { var spinResult = prizes[Math.floor(Math.random() * prizes.length)]; currentPrize = spinResult; // Add to history spinHistory.unshift({ user: username, prize: spinResult, time: new Date().toLocaleTimeString() }); // Keep only last 10 spins in history if (spinHistory.length > 10) { spinHistory.pop(); } // Show animation if enabled if (cb.settings.show_spin_animation === 'Yes') { showSpinAnimation(username, spinResult); } else { // Just announce the result cb.sendNotice( '🎰 ' + username + ' spun the wheel and won: ' + spinResult + ' 🎰', '', cb.settings.announce_color, '#FFFFFF', 'bold' ); } cb.drawPanel(); } /** * Show spin animation in chat */ function showSpinAnimation(username, result) { var spinSymbols = ['🎰', '🎲', '🎯', '🎪', '⭐', '💫', '✨', '🌟']; var randomSymbols = []; for (var i = 0; i < 3; i++) { randomSymbols.push(spinSymbols[Math.floor(Math.random() * spinSymbols.length)]); } cb.sendNotice( '╔══════════════════════════════════╗\n' + '║ ' + randomSymbols[0] + ' SPINNING THE WHEEL ' + randomSymbols[0] + ' ║\n' + '║ ' + randomSymbols.join(' ') + ' → 🎰 🎰 🎰 ║\n' + '╠══════════════════════════════════╣\n' + '║ ' + username + ' won: ║\n' + '║ ★ ' + result + ' ║\n'.substring(0, 36) + '╚══════════════════════════════════╝', '', cb.settings.announce_color, '#FFFFFF', 'bold' ); } /** * Update the room subject */ function updateSubject() { var remaining = tipsRemaining(); if (remaining === 0) { if (subjectIsSetWithZero) { return; } subjectIsSetWithZero = true; } else { subjectIsSetWithZero = false; } var newSubject = cb.settings.goal_description + ' | Spin for ' + cb.settings.spin_cost + ' tokens' + ' [' + remaining + ' tokens to goal]'; cb.log('Changing subject to: ' + newSubject); cb.changeRoomSubject(newSubject); } /** * Calculate remaining tokens to goal */ function tipsRemaining() { var remaining = cb.settings.token_goal - totalTipped; return remaining < 0 ? 0 : remaining; } /** * Show prizes to all users */ function showPrizes() { var msg = '🎰 ═══ ROULETTE PRIZES ═══ 🎰\n'; for (var i = 0; i < prizes.length; i++) { msg += ' ' + (i + 1) + '. ' + prizes[i] + '\n'; } msg += '═══════════════════════════\n'; msg += 'Tip ' + cb.settings.spin_cost + ' tokens to spin!'; cb.sendNotice(msg, '', cb.settings.announce_color, '#FFFFFF', 'bold'); } /** * Show prizes to a specific user */ function showPrizesToUser(username) { var msg = '🎰 ═══ ROULETTE PRIZES ═══ 🎰\n'; for (var i = 0; i < prizes.length; i++) { msg += ' ' + (i + 1) + '. ' + prizes[i] + '\n'; } msg += '═══════════════════════════\n'; msg += 'Tip ' + cb.settings.spin_cost + ' tokens to spin!'; cb.sendNotice(msg, username); } /** * Show recent spin history */ function showSpinHistory(username) { if (spinHistory.length === 0) { cb.sendNotice('No spins yet! Be the first to spin!', username); return; } var msg = '🎰 ═══ RECENT SPINS ═══ 🎰\n'; for (var i = 0; i < spinHistory.length; i++) { var spin = spinHistory[i]; msg += ' • ' + spin.user + ': ' + spin.prize + '\n'; } cb.sendNotice(msg, username); } /** * Show statistics */ function showStats(username) { var msg = '📊 ═══ ROULETTE STATS ═══ 📊\n'; msg += ' • Total Tipped: ' + totalTipped + ' / ' + cb.settings.token_goal + ' tokens\n'; msg += ' • Total Spins: ' + spinHistory.length + '\n'; if (highTipUsername) { msg += ' • Highest Tipper: ' + highTipUsername + ' (' + highTipAmount + ' tokens)\n'; } if (lastTipUsername) { msg += ' • Last Tip: ' + lastTipUsername + ' (' + lastTipAmount + ' tokens)\n'; } cb.sendNotice(msg, username); } /** * Show help/commands */ function showHelp(username) { var msg = '🎰 ═══ ROULETTE COMMANDS ═══ 🎰\n'; msg += ' /prizes - View all possible prizes\n'; msg += ' /spin - View spin info\n'; msg += ' /history - View recent spins\n'; msg += ' /stats - View statistics\n'; msg += ' /help or /roulette - Show this help\n'; msg += '═══════════════════════════════\n'; msg += 'Tip ' + cb.settings.spin_cost + ' tokens to spin the wheel!'; cb.sendNotice(msg, username); } /** * Show welcome message */ function showWelcome() { var msg = '🎰 ═══════════════════════════════ 🎰\n'; msg += ' Welcome to the Token Roulette!\n'; msg += '🎰 ═══════════════════════════════ 🎰\n'; msg += '\n'; msg += '💰 Tip ' + cb.settings.spin_cost + ' tokens to spin the wheel!\n'; msg += '🎁 ' + prizes.length + ' amazing prizes to win!\n'; msg += '\n'; msg += '📝 Commands:\n'; msg += ' /prizes - See all prizes\n'; msg += ' /spin - Spin info\n'; msg += ' /help - All commands\n'; cb.sendNotice(msg, '', cb.settings.announce_color, '#FFFFFF', 'bold'); } /** * Initialize the app */ function init() { // Load prizes from settings prizes = []; prizes.push(cb.settings.prize_1); prizes.push(cb.settings.prize_2); if (cb.settings.prize_3) { prizes.push(cb.settings.prize_3); } if (cb.settings.prize_4) { prizes.push(cb.settings.prize_4); } if (cb.settings.prize_5) { prizes.push(cb.settings.prize_5); } if (cb.settings.prize_6) { prizes.push(cb.settings.prize_6); } if (cb.settings.prize_7) { prizes.push(cb.settings.prize_7); } if (cb.settings.prize_8) { prizes.push(cb.settings.prize_8); } // Set initial prize currentPrize = prizes[0]; // Update room subject updateSubject(); // Show welcome message showWelcome(); cb.log('Roulette App initialized with ' + prizes.length + ' prizes'); } // ============================================ // START THE APP // ============================================ init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.