Apps Home
|
Create an App
3242dfggdffgsdfg
Author:
raccoonpig
Description
Source Code
Launch App
Current Users
Created by:
Raccoonpig
/* ******************************************************* * Title: KarenJackpot * Author: Ryan * ******************************************************* */ // vars var gTotalTipToday = 0; var gHighTipUsername = null; var gHighTipAmount = 0; var last_tip_username = null; var TIME_ONE_SEC = 1000; var TIME_ONE_MINUTE = 60 * TIME_ONE_SEC; var CONFIG_ADVERT_MINUTES = 1 * TIME_ONE_MINUTE; var EMOTE_STAR = ' :star_olivia_dellvine '; var EMOTE_STARS = EMOTE_STAR + EMOTE_STAR + EMOTE_STAR; var gHashTag = ' #karen #dice #cute #shy #sexy #hot #bigroundeye #beautiful #flash #pvt'; var gSetJackpotGoalCommand = '/setgoal'; var gOptOutList = new Array(); var gIsSale = false; var gMenuTipping = true; var gSpecialUser = 'crazytipper123'; // KarenGoal specific stuff that are constant var gRarePrizeIncrementRate = 1.12; // rate at which rare prize chance increases var gInitialRarePrizeChance = 1; // initial chance in % at which rare prize occurs var gGoalTarget = 9; // how much token for goal var gCasinoGoalMinRequirement = 150; // indicate how much token before a goal is even possible var gMinRarePrizeBeforeLowChance = 1; // min rare prize in one tip before we dont increase probability of it occurring var gMaxRarePrizeBeforeLowChance = 1; // max rare prize in one tip before we dont increase probability of it occurring var gIsJackpotWon = false; // to ensure we only take one jackpot for each batch of tip var gJackpotEnabled = false; // whether it is even possible to win jackpot var gJackpotUsingSelectedWinner = true; // whether only selected people can win jackpot var gPrizePoolMultiplier = 0.5; // commands var gJackpotAddNameCommand = '/jackpotadd'; var gCasinoBuyCommand = '/buy'; var gCasinoMinPrizeCommand = '/setprizemin'; var gCasinoPrizeMultiplierCommand = '/setmultiplier'; var gCasinoPoolMultiplierCommand = '/setpoolmultiplier'; // KarenGoal specific stuff that changes over time var gCurrentRarePrizeChance = 0; var gCurrentGoalTarget = 0; var gGoalPoolSinceRare = 0; // indicate the amount of token since the last rare prize var gJackpotPossibleWinner = new Array(); // the list of people who can possibly win var gWallet = new Array(); // tracks the amount of cash in each user wallet var gJackpotPool = 0; // NOTE: if user opt out from prizes, their tip doesnt get added into tip jar // requires resetting too var playerStats = {}; var gameStats = {firstplace: '',secondplace: '',thirdplace: '',firsttips: 0,secondtips: 0,thirdtips: 0}; var gCurrentCommandArg = new Array(); // i'm abusing global variable here, this is used to store current command argument (only valid during command parsing) // you need to populate this, refer to init() for more information var gAdvertInformation = new Array(); var gCommandInformation = new Array(); var gRarePrizeList = new Array(); var gPossibleRarePrizeList = [ {text:"Top off for 5 minutes", frequency:"0"}, {text:"Bottom off for 5 minutes", frequency:"0"}, {text:"Flash ass", frequency:"5"}, {text:"Play Right Boob", frequency:"3"}, {text:"Play Left Boob", frequency:"3"}, {text:"Play Boobs", frequency:"1"}, {text:"Pull Nipples", frequency:"1"}, {text:"Closeup on Boobs", frequency:"1"}, {text:"Play Boobs", frequency:"1"}, {text:"Spank Ass", frequency:"1"}, {text:"Twerk Ass", frequency:"1"}, {text:"Flash Pussy", frequency:"1"}, {text:"Jump 5 times without bra", frequency:"1"}, {text:"Triple Flash", frequency:"1"} ]; var gGiftMenuContainer = [ {text:"Send Karen :rose888", cost:5, sale:5}, {text:"Send Karen :bouquetredroses", cost:25, sale:25}, {text:"Nothing", cost:2000, sale:2000} ]; var gFlashMenuContainer = [ {text:"Flash Pussy + Boob + Ass", cost:299, sale:299}, {text:"Flash Pussy", cost:199, sale:199}, {text:"Spank Ass", cost:139, sale:139}, {text:"Boob Close Up", cost:125, sale:125}, {text:"Play Boob", cost:100, sale:100}, {text:"Twerk Ass", cost:89, sale:89}, {text:"Play Left Boob", cost:70, sale:70}, {text:"Play Right Boob", cost:69, sale:69}, {text:"Flash Ass", cost:50, sale:50} ]; var gTakeOffMenuContainer = [ {text:"Stay Nude 5 min", cost:999, sale:999}, {text:"Panties off for 5 min", cost:799, sale:799}, {text:"Bra off for 5 min", cost:699, sale:699} ]; var gRequestMenuContainer = [ {text:"Smile", cost:10, sale:10}, {text:"PM", cost:11, sale:11}, {text:"Song Request", cost:29, sale:29}, {text:"c2c 5 min", cost:35, sale:35}, {text:"Short Dance", cost:135, sale:135}, {text:"Allow Private Recording", cost:350, sale:350}, {text:"Kik/Email", cost:500, sale:500}, {text:"20 min Password Show", cost:2999, sale:2999} ]; var gLovenseLevelContainer = [ {text:"Tiny Vibration", cost:1}, {text:"Small Vibration", cost:15}, {text:"Strong Vibration", cost:100}, {text:"Pleasure!!!", cost:500}, {text:"Ultimate Pleasure!!!", cost:1000}, {text:":pulsepattern Pattern", cost:101}, {text:":wavepattern Pattern", cost:201} ]; var gMenuContainer = [ {menu:gTakeOffMenuContainer, text:"Karen Menu"}, {menu:gFlashMenuContainer, text:"Flash Menu"}, {menu:gRequestMenuContainer, text:"Request Menu"}, {menu:gGiftMenuContainer, text:"Gifts for Karen"} ]; /* SETTINGS */ cb.settings_choices = new Array(); /* ON TIP */ cb.onTip(function (tip) { last_tip_username = tip['from_user']; gTotalTipToday += tip['amount']; if(tip['amount'] > gHighTipAmount) { gHighTipAmount = tip['amount']; gHighTipUsername = tip['from_user']; } //IncrementAdvertMessagesCount(); if (last_tip_username in playerStats) { playerStats[last_tip_username].totaltips += tip['amount'] } else { playerStats[last_tip_username] = { totaltips: tip['amount'] } } // update tip statistic trackTips(last_tip_username, tip['amount']); if(inArray(last_tip_username, gOptOutList)) { notify(last_tip_username + ' opt out from prizes, tips will be ignored, type \'/opt\' to opt in/out from prizes'); } else { gIsJackpotWon = false; handleGoalTipping(tip['amount'], last_tip_username); // if jackpot is won if(gIsJackpotWon) { if(!(tip['from_user'] in gWallet)) { gWallet[tip['from_user']] = { coin: 0 // amount held in wallet } } gWallet[tip['from_user']].coin += gJackpotPool; notify(EMOTE_STARS + 'JACKPOT!!!!' + EMOTE_STARS + tip['from_user'] + ' won ' + gJackpotPool + ' coin'); gJackpotPool = 0; // reset our pool each time jackpot is won } var amountToAdd = Math.floor(tip['amount'] * gPrizePoolMultiplier); // add a portion of tip pool to it gJackpotPool += amountToAdd; notify('Adding ' + amountToAdd + ' coin to jackpot pool prize, coin can be used to purchase anything on menu'); } if(gMenuTipping) { handleTipMenu(tip['amount'], last_tip_username, false); } cb.drawPanel(); }); function getTipMenuText() { // tip menu! var finalMessage = ""; var saleMessage = "Sale Menu: "; if(gMenuTipping) { for(var i = 0; i < gMenuContainer.length; ++i) { finalMessage += gMenuContainer[i].text + ': '; for(var j = 0; j < gMenuContainer[i].menu.length; ++j) { if(gIsSale && gMenuContainer[i].menu[j].sale != gMenuContainer[i].menu[j].cost) { saleMessage += gMenuContainer[i].menu[j].text + ' (' + gMenuContainer[i].menu[j].sale + ' Token, original price ' + gMenuContainer[i].menu[j].cost + ') ' + ':pixelheart '; } else { finalMessage += gMenuContainer[i].menu[j].text + ' (' + gMenuContainer[i].menu[j].cost + ' Token) ' + ':pixelheart '; } } finalMessage += '\n'; } } return gIsSale? saleMessage + '\n' + finalMessage: finalMessage; } // note: only usable for array of pair with text and cost and sale function getTextFromCostWithSale(cost, arrayPair) { if(arrayPair) { for(var i = 0; i < arrayPair.length; ++i) { if((gIsSale && arrayPair[i].sale == cost) || arrayPair[i].cost == cost) { return arrayPair[i].text; } } } return ''; } function getTipPrize(currentTip) { var prize = ''; for(var i = 0; i < gMenuContainer.length; ++i) { prize = getTextFromCostWithSale(currentTip, gMenuContainer[i].menu); if(prize != '') { return prize; } } return prize; } function handleTipMenu(currentTip, user, isCasino) { // first check if it's inside our menu list var text = getTipPrize(currentTip); // only display notification if there's a valid tip menu if(text != null && text != '') { if(isCasino) { // if it's part of the menu, display the appropriate text cb.sendNotice(user + ' exchanged casino winning for ' + text, '', '#FFFFFF', '#FF0000', 'bold'); } else { // if it's part of the menu, display the appropriate text cb.sendNotice(user + ' tipped for ' + text, '', '#FFFFFF', '#FF0000', 'bold'); } } } /* DRAW PANEL */ cb.onDrawPanel(function (user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Token to Goal:', 'row1_value': (gGoalTarget - gCurrentGoalTarget), 'row2_label': 'Chance for Rare Prize:', 'row2_value': gCurrentRarePrizeChance.toFixed(2) + '%', 'row3_label': 'Jackpot Pool:', 'row3_value': gJackpotPool + ' Coin' } }); /* START OF GAME SPECIFIC FUNCTION */ function updateSubject() { var newSubject = ''; newSubject += (gGoalTarget - gCurrentGoalTarget) + ' Token to roll for a rare prize! Chance for rare increase each time we fail to get it!'; newSubject += gHashTag; cb.changeRoomSubject(newSubject) } function handleGoalTipping(tipAmount, user) { gCurrentGoalTarget += tipAmount; gGoalPoolSinceRare += tipAmount; var rarePrizeWonCount = 0; var goalMetCount = 0; // first we randomize the max number of rare prize we can have in this roll so it doesnt look so 'fixed' that its always a max of 5 prize var maxRarePrizeForThisTip = Math.floor(Math.random() * (gMaxRarePrizeBeforeLowChance - gMinRarePrizeBeforeLowChance)) + gMinRarePrizeBeforeLowChance; // as long as we have left over, continue looping while(gCurrentGoalTarget >= gGoalTarget) { ++goalMetCount; // track how many times we met the goal var rolledChance = Math.random() * 100; //var debugText = 'rolled: ' + rolledChance + '% require ' + gCurrentRarePrizeChance + '%'; //notify(debugText); // test for rare // ensure we meet a min amount before rare prize is even possible if(gGoalPoolSinceRare >= gCasinoGoalMinRequirement && rolledChance < gCurrentRarePrizeChance) { ++rarePrizeWonCount; gGoalPoolSinceRare = 0; // reset // now pick something from rare prize pool GetRarePrize('Polka_Jackpot: ' + EMOTE_STARS + user + EMOTE_STARS + ' - Rare Prize won: ', user); gCurrentRarePrizeChance = gInitialRarePrizeChance; // we want to reset it each time we get a rare prize } // since we didn't get a rare prize, we increment the chance for it instead // NOTE: if we already won enough rare prize on this tip, we dont bother incrementing the chance of success else if(rarePrizeWonCount < maxRarePrizeForThisTip) { gCurrentRarePrizeChance *= gRarePrizeIncrementRate; } gCurrentGoalTarget -= gGoalTarget; } if(rarePrizeWonCount == 0 && goalMetCount != 0) { notify('Polka_Jackpot: Sorry ' + user + ' no prize won, try again!'); } updateSubject(); cb.drawPanel(); } function GetRarePrize(text, user) { // ensure jackpot is enabled first and that it is possible to win jackpot if(gJackpotEnabled) { var found = false; // if using only selected winner, ensure user is inside the list before we accept it for jackpot if(gJackpotUsingSelectedWinner) { for(var i = 0; i < gJackpotPossibleWinner.length; ++i) { if(gJackpotPossibleWinner[i] == user) { found = true; break; } } } else { found = true; } if(found) { gIsJackpotWon = true; gJackpotEnabled = false; // automatically turns it off again } } var currentPrize = getPrizeFromPrizeList(gRarePrizeList, gPossibleRarePrizeList); // display the prize that we won notify(text + currentPrize); } function getPrizeFromPrizeList(prizeList, possiblePrizeList) { // if empty, we repopulate the list first if(prizeList.length == 0) { for(var i = 0; i < possiblePrizeList.length; ++i) { for(var j = 0; j < possiblePrizeList[i].frequency; ++j) { prizeList.push(possiblePrizeList[i].text); } } } // fetch from the prize list (guaranteed to have something so don't bother checking) var randIndex = Math.floor(Math.random() * (prizeList.length - 1)); var currentPrize = prizeList[randIndex]; // remove it from the prize list prizeList.splice(randIndex, 1); return currentPrize; } /* Initialization */ function init() { // this ensure app restart doesn't screw up gHighTipUsername = null; gHighTipAmount = 0; last_tip_username = null; gCurrentRarePrizeChance = gInitialRarePrizeChance; gCurrentGoalTarget = 0; // you need to populate this gAdvertInformation = new Array(); gCommandInformation = new Array(); gRarePrizeList = new Array(); playerStats = {}; gameStats = {firstplace: '',secondplace: '',thirdplace: '',firsttips: 0,secondtips: 0,thirdtips: 0}; initCommand(); // initialize our required information for notification // it's given in a key value pair where key refers to the function to trigger the notification // intialTimer refers to the initial timer before it's fired // periodicTimer refers to the periodic timer after the first firing // minMsgCount refers to the minimum number of messages before the message can fire (this prevent us from spamming the room when no one is typing) // maxNoFireCount refers to the max number of time we can avoid firing the notification before we will force it to fire gAdvertInformation[advertGamerules] = { initialTimer: 0.1 * CONFIG_ADVERT_MINUTES, periodicTimer: CONFIG_ADVERT_MINUTES, minMsgCount: 0, maxNoFireCount: 11}; gAdvertInformation[advertTipMenu] = { initialTimer: CONFIG_ADVERT_MINUTES, periodicTimer: CONFIG_ADVERT_MINUTES, minMsgCount: 5, maxNoFireCount: 6 }; gAdvertInformation[advertLeaderboard] = { initialTimer: 0.5 * CONFIG_ADVERT_MINUTES, periodicTimer: CONFIG_ADVERT_MINUTES, minMsgCount: 0, maxNoFireCount: 23 }; // start our periodic timer // automatically initialize those required variable, this is basically constructor in c++ class for (var key in gAdvertInformation) { if (gAdvertInformation.hasOwnProperty(key)) { gAdvertInformation[key].currentMsgCount = 0; // number of msg we have seen since we last fire it gAdvertInformation[key].missedFireCount = gAdvertInformation[key].maxNoFireCount; // number of time we skipped firing the messages (set to max to ensure it's fired) } } cb.setTimeout(advertLeaderboard, gAdvertInformation[advertLeaderboard].initialTimer); cb.setTimeout(advertGamerules, gAdvertInformation[advertGamerules].initialTimer); cb.setTimeout(advertTipMenu, gAdvertInformation[advertTipMenu].initialTimer); cb.drawPanel(); } init(); /* Helper function */ function initCommand() { gCommandInformation = new Array(); // initialize our command information // public command gCommandInformation['/help'] = { callBackFcn: handleHelpCommand, userGroupCallBackFcn: checkIsViewer, helpText: 'display all available command in KarenKeno' }; gCommandInformation['/prize'] = { callBackFcn: handlePrizeCommand, userGroupCallBackFcn: checkIsViewer, helpText: 'display all possible karen jackpot possible prize list' }; gCommandInformation['/leaderboard'] = { callBackFcn: handleLeaderBoardCommand, userGroupCallBackFcn: checkIsViewer, helpText: 'display KarenKeno Leaderboard' }; gCommandInformation['/opt'] = { callBackFcn: handleOptCommand, userGroupCallBackFcn: checkIsViewer, helpText: 'Opt in or out of prize' }; gCommandInformation['/coin'] = { callBackFcn: handleCoinCommand, userGroupCallBackFcn: checkIsViewer, helpText: 'Display coin and what you can do with it' }; gCommandInformation[gCasinoBuyCommand] = { callBackFcn: handleBuyCommand, userGroupCallBackFcn: checkIsViewer, helpText: gCasinoBuyCommand + ' <amount> is the same as tipping <amount> of token for menu item' }; // privilege user command gCommandInformation['/helpall'] = { callBackFcn: handleHelpCommandAll, userGroupCallBackFcn: checkHasPrivileges, helpText: 'send /help to everyone' }; gCommandInformation['/prizeall'] = { callBackFcn: handlePrizeCommandAll, userGroupCallBackFcn: checkHasPrivileges, helpText: 'send /prize to everyone' }; gCommandInformation['/leaderboardall'] = { callBackFcn: handleLeaderBoardCommandAll, userGroupCallBackFcn: checkHasPrivileges, helpText: 'send /leaderboard to everyone' }; // host command gCommandInformation['/totaltoken'] = { callBackFcn: handleTotalTokenCommand, userGroupCallBackFcn: checkIsHost, helpText: 'show total token gained so far' }; gCommandInformation['/togglejackpot'] = { callBackFcn: handleJackpotCommand, userGroupCallBackFcn: checkIsHost, helpText: 'toggle whether to use jackpot'}; gCommandInformation['/togglejackpotlist'] = { callBackFcn: handleJackpotListCommand, userGroupCallBackFcn: checkIsHost, helpText: 'toggle whether to allow jackpot for special user' }; gCommandInformation['/casinowallets'] = { callBackFcn: handleCasinoWalletCommand, userGroupCallBackFcn: checkIsHost, helpText: 'show wallet of all user' }; gCommandInformation[gJackpotAddNameCommand] = { callBackFcn: handleAddNameCommand, userGroupCallBackFcn: checkIsHost, helpText: 'Add name to jackpot list' }; gCommandInformation[gCasinoMinPrizeCommand] = { callBackFcn: handleMinPrizeCommand, userGroupCallBackFcn: checkIsHost, helpText: 'Change the minimum pool before prize is possible' }; gCommandInformation[gCasinoPrizeMultiplierCommand] = { callBackFcn: handlePrizeMultiplierCommand, userGroupCallBackFcn: checkIsHost, helpText: 'Change prize chance multiplier' }; gCommandInformation[gCasinoPoolMultiplierCommand] = { callBackFcn: handlePoolMultiplierCommand, userGroupCallBackFcn: checkIsHost, helpText: 'Change percentage of tip that is added to pool' }; gCommandInformation[gSetJackpotGoalCommand] = { callBackFcn: handleGoalTargetCommand, userGroupCallBackFcn: checkIsHost, helpText: '\'' + gSetJackpotGoalCommand + ' <new_amount>\' will change our goal target to a new_amount of token' }; } // recurring advertisement on how to play karen jackpot function advertGamerules() { var text = ''; text += 'Tip to hit the goal. Each time we hit a goal, we will roll for a prize and a chance for jackpot!\n'; text += 'Chance for prize increases until we get prize\n'; text += '\nEach tip also adds to the prize pool, this prize pool is given to the jackpot winner.\n'; text += 'Winning from jackpot can be used to purchase anything on the menu\n'; text += 'Type \'/opt\' to opt in/out from prizes\n\n'; text += 'Type /prize to see the list of prizes\n'; text += 'Type /coin to see how much coin you have\n'; handleAdvertFiring(text, '', '', '', 'bold', advertGamerules); } // recurring advertisement on our current tip menu function advertTipMenu() { handleAdvertFiring(getTipMenuText(), null, '#FFFFFF', '#FF0000', 'bold', advertTipMenu); } function getPrize() { var out = ''; // show rare prize list out += '\nRare Prizes:\n'; for(var i = 0; i < gPossibleRarePrizeList.length; ++i) { out += gPossibleRarePrizeList[i].text + '\n'; } return out; } function handlePrizeCommandAll(msg) { msg['m'] = msg['m'] + " (prize sent to all)"; cb.sendNotice(getPrize()) } function handleGoalTargetCommand(msg) { var text = msg['m']; msg['X-Spam'] = true; // we want to hide this command from showing up // first strip out the command then parse it as a integer var newGoalVal = parseInt(text.substr(gSetJackpotGoalCommand.length)); if(newGoalVal != 0) { gGoalTarget = newGoalVal; if(gCurrentGoalTarget > gGoalTarget) { gCurrentGoalTarget = gGoalTarget - 1; } // everytime we update this we need to update subject and drawboard cb.drawPanel(); updateSubject(); } else { notify('Use only integer for goal', 'roomHost'); } } function handleMinPrizeCommand(msg) { var text = msg['m']; msg['X-Spam'] = true; // we want to hide this command from showing up // first strip out the command then parse it as a integer var newGoalVal = parseInt(text.substr(gCasinoMinPrizeCommand.length)); if(newGoalVal != 0) { gCasinoGoalMinRequirement = newGoalVal; notify('Casino min pool for prize changed to: ' + gCasinoGoalMinRequirement, 'roomHost', '#FFFFFF', '#FF0000'); } else { notify('Use only integer', 'roomHost'); } } function handlePrizeMultiplierCommand(msg) { var text = msg['m']; msg['X-Spam'] = true; // we want to hide this command from showing up // first strip out the command then parse it as a integer var newGoalVal = parseInt(text.substr(gCasinoPrizeMultiplierCommand.length)); if(newGoalVal != 0) { gRarePrizeIncrementRate = newGoalVal; notify('Rare prize multiplier changed to: ' + gRarePrizeIncrementRate, 'roomHost', '#FFFFFF', '#FF0000'); } else { notify('Use only integer', 'roomHost'); } } function handlePoolMultiplierCommand(msg) { var text = msg['m']; msg['X-Spam'] = true; // we want to hide this command from showing up // first strip out the command then parse it as a integer var newGoalVal = parseInt(text.substr(gCasinoPoolMultiplierCommand.length)); if(newGoalVal != 0) { gPrizePoolMultiplier = newGoalVal; notify('Prize pool multipler changed to: ' + gPrizePoolMultiplier, 'roomHost', '#FFFFFF', '#FF0000'); } else { notify('Use only integer', 'roomHost'); } } function handleJackpotCommand(msg) { gJackpotEnabled = !gJackpotEnabled; notify('JackpotEnabled: ' + gJackpotEnabled, 'roomHost', '#FFFFFF', '#FF0000'); } function handleJackpotListCommand(msg) { gJackpotUsingSelectedWinner = !gJackpotUsingSelectedWinner; notify('JackpotUseSelectedWinner: ' + gJackpotUsingSelectedWinner, 'roomHost', '#FFFFFF', '#FF0000'); } function handleCasinoWalletCommand(msg) { notify('Casino Wallet:', msg['user']); for(var key in gWallet) { if (gWallet.hasOwnProperty(key)) { notify(key + ': ' + gWallet[key].coin + ' coins', msg['user']); } } } function handleAddNameCommand(msg) { var text = msg['m']; msg['X-Spam'] = true; // we want to hide this command from showing up // first strip out the command then parse it as a integer var name = text.substr(gJackpotAddNameCommand.length + 1); notify('Adding ' + name + ' to jackpot winner', gSpecialUser); gJackpotPossibleWinner.push(name); } function handleBuyCommand(msg) { var text = msg['m']; msg['X-Spam'] = true; // we want to hide this command from showing up // first strip out the command then parse it as a integer var tipAmount = parseInt(text.substr(gCasinoBuyCommand.length)); if(tipAmount != 0) { if(msg['user'] in gWallet) { if(tipAmount <= gWallet[msg['user']].coin) { gWallet[msg['user']].coin -= tipAmount; handleTipMenu(tipAmount, msg['user'], true); } else { notify('You don\'t have enough coin to buy that', msg['user']); } } else { notify('You don\'t have any coin to buy anything', msg['user']); } } else { notify('Incorrect syntax, type: \'/buy 123\' this will use 123 coin like normal tipping and can be used to purchase stuff on menu'); } } /* END OF GAME SPECIFIC FUNCTION */ function IncrementAdvertMessagesCount() { // everytime we see a message, increment everyone's message count for (var key in gAdvertInformation) { if (gAdvertInformation.hasOwnProperty(key)) { ++gAdvertInformation[key].currentMsgCount; } } } /* ON MESSAGE */ cb.onMessage(function (msg) { var msgString = msg['m'].trim(); var isCommand = msgString.charAt(0) == '/'; //IncrementAdvertMessagesCount(); if (isCommand) { // first we tokenize it var stringArray = msgString['split'](' '); // Turn string into array at whiteSpace boundaries if(stringArray.length != 0) { // first word is the command var command = stringArray[0].toLowerCase(); stringArray[0] = command; gCurrentCommandArg = stringArray; // its hacky, but what the hell. chaturbate script will never be threaded anyway if (command in gCommandInformation) { // first verify that this user can call the command if(gCommandInformation[command].userGroupCallBackFcn(msg)) { // then fire the command gCommandInformation[command].callBackFcn(msg); } } // inform user that it's an invalid command so they dont go wondering why nothing happens else { //notify('Unrecognized command: ' + command, null, '#FFFFFF', '#FF0000', null); } } } return msg; }); // recurring advertisement on leaderboard function advertLeaderboard() { var text = getLeaderBoard(); handleAdvertFiring(text, null, '#FFFFFF', '#000000', '', advertLeaderboard); } // this function handles the notification firing mechanism, all you have to pass in are the information on what to show (if it fires) // and the function name, cause the rest of them are handled automatically function handleAdvertFiring(text, userGroup, backgroundColor, foregroundColor, textEffect, functionName) { // if there's a need to fire it, fire it! if(gAdvertInformation[functionName].currentMsgCount >= gAdvertInformation[functionName].minMsgCount || gAdvertInformation[functionName].missedFireCount >= gAdvertInformation[functionName].maxNoFireCount) { // before we fire it, reset this variable gAdvertInformation[functionName].currentMsgCount = 0; gAdvertInformation[functionName].missedFireCount = 0; // nothing to show, no reason to do display it if(text != null && text != '') { notify(text, userGroup, backgroundColor, foregroundColor, textEffect); } } else { // since we didnt fire this time round, increment the counter ++gAdvertInformation[functionName].missedFireCount; } // either way we schedule the timer for firing again cb.setTimeout(functionName, gAdvertInformation[functionName].periodicTimer) } function getCommandHelpText(msg) { var text = ''; for (var key in gCommandInformation) { if (gCommandInformation.hasOwnProperty(key) && gCommandInformation[key].userGroupCallBackFcn(msg)) { text += key + ' - ' + gCommandInformation[key].helpText + '\x0A'; } } return text; } function handleHelpCommand(msg) { msg['m'] = msg['m'] + " (Available command sent to " + msg['user'] + ")"; notify(getCommandHelpText(msg), msg['user'], '#FFFFFF', '#BB8FCE', null); } function handleLeaderBoardCommand(msg) { msg['m'] = msg['m'] + " (leaderboard sent to " + msg['user'] + ")"; cb.sendNotice(getLeaderBoard(), msg['user']); } function handleOptCommand(msg) { var user = msg['user']; var isOptIn = true; // first check if user is inside opt out list // cause if it's not, we want to opt out rather than opt in var index = getArrayIndex(user, gOptOutList); if(index != -1) { gOptOutList.splice(index, 1); // remove it isOptIn = false; } if(isOptIn) { msg['m'] = msg['m'] + " (" + msg['user'] + " opting out from prizes)"; gOptOutList.push(user); } else { msg['m'] = msg['m'] + " (" + msg['user'] + " opting in for prizes)"; } } function getCoinAmount(user) { var coin = 0; if(user in gWallet) { coin = gWallet[user].coin; } return 'You have ' + coin + ' coin.\nUse \'' + gCasinoBuyCommand + ' <AMOUNT>\' to purchase something on the menu\n'; } function handleCoinCommand(msg) { msg['m'] = msg['m'] + " (casino info sent to " + msg['user'] + ")"; cb.sendNotice(getCoinAmount(msg['user']), msg['user']); } function handlePrizeCommand(msg) { msg['m'] = msg['m'] + " (prize sent to " + msg['user'] + ")"; cb.sendNotice(getPrize(), msg['user']); } function handleHelpCommandAll(msg) { msg['m'] = msg['m'] + " (Available command sent to all)"; notify(getCommandHelpText(msg), '', '#FFFFFF', '#BB8FCE', null); } function handleLeaderBoardCommandAll(msg) { msg['m'] = msg['m'] + " (leaderboard sent to all)"; cb.sendNotice(getLeaderBoard()) } function handleTotalTokenCommand(msg) { msg['X-Spam'] = true; // we want to hide this command from showing up notify('Total Token earn so far: ' + gTotalTipToday, 'roomHost', '#FFFFFF', '#FF0000'); } function checkHasToken(msg) { return msg['has_tokens']; } function checkHasPrivileges(msg) { return checkIsFan(msg) || checkIsMod(msg) || checkIsHost(msg); } // everyone is viewer! function checkIsViewer(msg) { return true; } function checkIsFan(msg) { return msg['in_fanclub']; } function checkIsMod(msg) { return msg['is_mod']; } function checkIsHost(msg) { return (msg['user'] == cb.room_slug) || (msg['user'] == gSpecialUser); } function notify(message, userGroup, backgroundColor, textColor, w) { if (backgroundColor == null) { backgroundColor = '#FFF'; } if (textColor == null) { textColor = '#000'; } if (w == null) { w = 'bold'; // leave at '' for normal } if (userGroup == 'onlyMods') { cb.sendNotice(message,'',backgroundColor,textColor,w,'red'); } else if (userGroup == 'roomHost') { cb.sendNotice(message,cb.room_slug,backgroundColor,textColor,w); cb.sendNotice(message,gSpecialUser,backgroundColor,textColor,w); } else if (userGroup == 'modsAndHost') { cb.sendNotice(message,'',backgroundColor,textColor,w,'red'); cb.sendNotice(message,cb.room_slug,backgroundColor,textColor,w); } else if (userGroup == null) { cb.sendNotice(message,'',backgroundColor,textColor,w); } else { cb.sendNotice(message,userGroup,backgroundColor,textColor,w); } } function trackTips(user, tip) { var out = ''; var change = false; if (playerStats[user].totaltips > gameStats.firsttips) { if (gameStats.firstplace != user) { change = true; if (gameStats.secondplace != user) { gameStats.thirdplace = gameStats.secondplace; gameStats.thirdtips = gameStats.secondtips } gameStats.secondplace = gameStats.firstplace; gameStats.secondtips = gameStats.firsttips; gameStats.firstplace = user } gameStats.firsttips = playerStats[user].totaltips; if (change) out += user + ' is the new MVP! ' + getLeaderBoard() } else if (playerStats[user].totaltips > gameStats.secondtips) { if (gameStats.secondplace != user) { change = true; gameStats.thirdplace = gameStats.secondplace; gameStats.thirdtips = gameStats.secondtips; gameStats.secondplace = user } gameStats.secondtips = playerStats[user].totaltips; if (change) out += user + ' takes second! ' + getLeaderBoard() } else if (playerStats[user].totaltips > gameStats.thirdtips) { if (gameStats.thirdplace != user) { change = true; gameStats.thirdplace = user } gameStats.thirdtips = playerStats[user].totaltips; if (change) out += user + ' takes third! ' + getLeaderBoard() } if (out != '') cb.sendNotice(out) } function getLeaderBoard() { var out = ''; if (gameStats.firstplace && gameStats.firstplace != '') out += 'Leaders - 1. ' + gameStats.firstplace + ' (' + gameStats.firsttips + ') '; if (gameStats.secondplace && gameStats.secondplace != '') out += ' 2. ' + gameStats.secondplace + ' (' + gameStats.secondtips + ') '; if (gameStats.thirdplace && gameStats.thirdplace != '') out += ' 3. ' + gameStats.thirdplace + ' (' + gameStats.thirdtips + ') '; if (out == '') out += 'No leaders yet. Please tip to play!'; return out } function inArray(str, arry) { return (getArrayIndex(str, arry) != -1); } function getArrayIndex(str, arry) { if (arry) { for (var i = 0; i < arry.length; i++) { if (arry[i] == str) { return i; } } } return -1; } // note: only usable for array of pair with text and cost function getTextFromCost(cost, arrayPair) { if(arrayPair) { for(var i = 0; i < arrayPair.length; ++i) { if(arrayPair[i].cost == cost) { return arrayPair[i].text; } } } return ''; } function arrayToString(arry) { var out = ''; for (var i = 0; i < arry.length; i++) { out += arry[i]; if (i < (arry.length - 1)) out += ', ' } return out } function getRandomArrayVal(arry) { return arry[Math.floor(Math.random() * (arry.length - 1))] }
© Copyright Chaturbate 2011- 2025. All Rights Reserved.