Apps Home
|
Create an App
TestingSeveralFunctions
Author:
magicstick
Description
Source Code
Launch App
Current Users
Created by:
Magicstick
// Variables var _total_tipped = 0; var _useGoal = false; var _goal = 500; var _goalText = 'goal text'; var _useAutoSubject = false; var _ticketPrice = 20; var _tags = 'tags'; var _subject = 'subject'; var _noticeColor = 'noticeColor'; var _noticeTime = 500; var _totalChance = 0; var _showOver = false; var _priceNumber = 0; var _tipper = 'ERR'; var _winningArray = new Array(); var _prices = new Array(); var _chances = new Array(); var _chancesToDisplay = new Array(); // Settings cb.settings_choices = [ { name: 'useAutoSubject', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No', label: '1. ROOM SETTINGS --------- Use automated subject?' }, { name: 'subject', type: 'str', required: false, label: 'Room subject:' }, { name: 'tags', type: 'str', required: false, defaultValue: 'lovense, cum', label: 'Tags (#):' }, { name: 'noticeColor', type: 'choice', choice1: 'Black', choice2: 'Blue', choice3: 'Green', choice4: 'Orange', choice5: 'Pink', choice6: 'Purple', choice7: 'Red', defaultValue: 'Red', label: '2. NOTICE SETTINGS --------- Color:' }, { name: 'noticeTime', type: 'int', minValue: 30, defaultValue: 300, label: 'How frequently shall the notice be printed? (in seconds):' }, { name: 'ticketPrice', type: 'int', defaultValue: 20, label: '3. LOTTERY SETTINGS --------- Set your ticket price:' }, { name: 'info', type: 'str', required: false, defaultValue: '(Do not change this one)', label: 'Set your prices and winning chances in the following. The percentages should add up to 100%! You need to use this syntax: name of price,percentage(without %) --- Example: Flash boobs,15.00' }, { name: 'price_chance1', type: 'str', defaultValue: 'price,0', label: '1st price' }, { name: 'price_chance2', type: 'str', defaultValue: 'price,0', label: '2nd price' }, { name: 'price_chance3', type: 'str', defaultValue: 'price,0', label: '3rd price' }, { name: 'price_chance4', type: 'str', required: false, label: '4th price' }, { name: 'price_chance5', type: 'str', required: false, label: '5th price' }, { name: 'price_chance6', type: 'str', required: false, label: '6th price' }, { name: 'price_chance7', type: 'str', required: false, label: '7th price' }, { name: 'price_chance8', type: 'str', required: false, label: '8th price' }, { name: 'price_chance9', type: 'str', required: false, label: '9th price' }, { name: 'price_chance10', type: 'str', required: false, label: '10th price' }, { name: 'price_chance11', type: 'str', required: false, label: '11th price' }, { name: 'price_chance12', type: 'str', required: false, label: '12th price' }, { name: 'price_chance13', type: 'str', required: false, label: '13th price' }, { name: 'price_chance14', type: 'str', required: false, label: '14th price' }, { name: 'price_chance15', type: 'str', required: false, label: '15th price' }, { name: 'useGoal', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', label: '4. GOAL SETTINGS --------- Use a goal?' }, { name: 'goal', type: 'int', defaultValue: 500, required: false, label: 'Set your goal:' }, { name: 'goalText', type: 'str', minLength: 1, required: false, defaultValue: 'Example: Cumshow', label: 'Define your goal (Will be added to the room\'s subject):' } ]; // Chaturbate functions function sendRoomNotice() { var message = ''; message += 'Super Goal Lottery! Ticket price: ' + _ticketPrice +' tokens \n'; for (var i = _prices.length - 1; i >= 0; i--) { message += '[' + _chancesToDisplay[i] + '%] ' + _prices[i] + '\n'; } message += 'Good luck everybody!'; cb.chatNotice(cb.sendNotice(message, '', '', _noticeColor, 'normal')); cb.setTimeout(sendRoomNotice, _noticeTime * 1000); } cb.onTip(function (tip) { _total_tipped += parseInt(tip['amount']); if(parseInt(tip['amount']) == _ticketPrice) buyTicket(tip['from_user']); if(_total_tipped >= _goal) { cb.sendNotice('GOAL REACHED!', '', '', _noticeColor, 'bolder'); changeRoomSubject(true); _showOver = true; } else changeRoomSubject(false); }); cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Goal progression :', 'row1_value': Math.round(_total_tipped / _goal * 100) + '%', 'row2_label': 'Recently won:', 'row2_value': _prices[_priceNumber], 'row3_label': 'Ticket Price:', 'row3_value': _ticketPrice }; }); // Helper functions function buyTicket(tipper) { var winNumber = getRandomInt(0, _totalChance); _priceNumber = 0; _tipper = tipper; cb.log(_totalChance); cb.log(winNumber); cb.log(_winningArray); for (var i = 0; i < _winningArray.length; i++) { if(winNumber > _winningArray[i] && winNumber <= _winningArray[i+1]) _priceNumber = i; } var message = _prices[_priceNumber] + ' has been won by ' + _tipper; cb.sendNotice(message, '', '', _noticeColor, 'normal'); cb.drawPanel() } function changeRoomSubject(goalMet) { var remainingTokens; if(!goalMet) remainingTokens = (_goal - _total_tipped) + ' tokens remaining'; else remainingTokens = 'Goal reached!' if(_useAutoSubject && _useGoal) _subject = 'Super Goal Lottery! ' + _goalText + ' [' + remainingTokens + '] '; else if(_useAutoSubject && !_useGoal) _subject = 'Super Goal Lottery! Get a ticket for ' + _ticketPrice + ' tokens'; else if(!_useAutoSubject && _useGoal) _subject += _goalText + ' [' + remainingTokens + '] '; _subject += _tags + ''; if(!_showOver) cb.changeRoomSubject(_subject); } function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min +1)) + min; } function init() { _total_tipped = 0; _useGoal = cb.settings.useGoal; _goal = cb.settings.goal; _goalText = cb.settings.goalText; _useAutoSubject = cb.settings.useAutoSubject; _ticketPrice = cb.settings.ticketPrice; _tags = cb.settings.tags; _noticeColor = cb.settings.noticeColor; _noticeTime = cb.settings.noticeTime; _subject = cb.settings.subject; var prices_chances = [cb.settings.price_chance1, cb.settings.price_chance2, cb.settings.price_chance3, cb.settings.price_chance4, cb.settings.price_chance5, cb.settings.price_chance6, cb.settings.price_chance7, cb.settings.price_chance8, cb.settings.price_chance9, cb.settings.price_chance10, cb.settings.price_chance11, cb.settings.price_chance12, cb.settings.price_chance13, cb.settings.price_chance14, cb.settings.price_chance15 ]; if(_useGoal == 'Yes') _useGoal = true; else _useGoal = false; var splitArray; for (i = 0; i < prices_chances.length; i++) { if(prices_chances[i]) { splitArray = prices_chances[i].split(',', 2); _prices.push(splitArray[0]); _chances.push(splitArray[1]); } } for (i = 0; i < _chances.length; i++) _chancesToDisplay[i] = Math.round(parseFloat(_chances[i]) * 100) / 100; if(_tags != '') { splitArray = String(_tags).split(','); var newTags = ''; for (var i = splitArray.length - 1; i >= 0; i--) { newTags += '#' + splitArray[i].replace(/\s/g, ''); } _tags = newTags; } if(_noticeColor == 'Black') _noticeColor = '#000000'; else if(_noticeColor == 'Blue') _noticeColor = '#0000b2'; else if(_noticeColor == 'Green') _noticeColor = '#006600'; else if(_noticeColor == 'Orange') _noticeColor = '#FFA500'; else if(_noticeColor == 'Pink') _noticeColor = '#e5acb6'; else if(_noticeColor == 'Purple') _noticeColor = '#800080'; else if(_noticeColor == 'Red') _noticeColor = '#990000'; for (var i = 0; i < _chances.length; i++) { if(i == 0) _winningArray.push(parseFloat(_chances[i])); else _winningArray.push(parseFloat(_chances[i]) + _totalChance); _totalChance += parseFloat(_chances[i]); } changeRoomSubject(false); cb.setTimeout(sendRoomNotice, _noticeTime); } init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.