Apps Home
|
Create an App
Simple Multi-Goal
Author:
thibmorozier
Description
Source Code
Launch App
Current Users
Created by:
Thibmorozier
// Title: Simple Multi-Goal // Author: ThibmoRozier // Version: 1.0 (2017-05-04) // Description: Allows the model to have up to 10 token goals without any superfluous stuff // Constants var timerInterval = 5 * 60 * 1000; // 5 minutes // Variables var totalTippedTokens = 0, highestTipperName = '', highestTipperTokens = 0, lastTipperName = '', lastTipperTokens = 0, lastGoalReached = false, activeGoal = 1; // CB API handlers cb.settings_choices = [ { name: 'tipGoalCount', label: 'Amount of active tip goals', type: 'choice', choice1: '1', choice2: '2', choice3: '3', choice4: '4', choice5: '5', choice6: '6', choice7: '7', choice8: '8', choice9: '9', choice10: '10', defaultValue: '1' }, { name: 'subjectPrefix', label: 'Subject prefix', type: 'str', minLength: 0, maxLength: 255, required: false }, { name: 'tokensOne', label: 'Token count for goal One', type: 'int', minValue: 1, default: 100, required: true }, { name: 'goalDescriptionOne', label: 'Description for goal One', type: 'str', minLength: 1, maxLength: 255, default: 'Description', required: true }, { name: 'tokensTwo', label: 'Token count for goal Two', type: 'int', minValue: 0, default: 0, required: false }, { name: 'goalDescriptionTwo', label: 'Description for goal Two', type: 'str', minLength: 1, maxLength: 255, required: false }, { name: 'tokensThree', label: 'Token count for goal Three', type: 'int', minValue: 0, default: 0, required: false }, { name: 'goalDescriptionThree', label: 'Description for goal Three', type: 'str', minLength: 1, maxLength: 255, required: false }, { name: 'tokensFour', label: 'Token count for goal Four', type: 'int', minValue: 0, default: 0, required: false }, { name: 'goalDescriptionFour', label: 'Description for goal Four', type: 'str', minLength: 1, maxLength: 255, required: false }, { name: 'tokensFive', label: 'Token count for goal Five', type: 'int', minValue: 0, default: 0, required: false }, { name: 'goalDescriptionFive', label: 'Description for goal Five', type: 'str', minLength: 1, maxLength: 255, required: false }, { name: 'tokensSix', label: 'Token count for goal Six', type: 'int', minValue: 0, default: 0, required: false }, { name: 'goalDescriptionSix', label: 'Description for goal Six', type: 'str', minLength: 1, maxLength: 255, required: false }, { name: 'tokensSeven', label: 'Token count for goal Seven', type: 'int', minValue: 0, default: 0, required: false }, { name: 'goalDescriptionSeven', label: 'Description for goal Seven', type: 'str', minLength: 1, maxLength: 255, required: false }, { name: 'tokensEight', label: 'Token count for goal Eight', type: 'int', minValue: 0, default: 0, required: false }, { name: 'goalDescriptionEight', label: 'Description for goal Eight', type: 'str', minLength: 1, maxLength: 255, required: false }, { name: 'tokensNine', label: 'Token count for goal Nine', type: 'int', minValue: 0, default: 0, required: false }, { name: 'goalDescriptionNine', label: 'Description for goal Nine', type: 'str', minLength: 1, maxLength: 255, required: false }, { name: 'tokensTen', label: 'Token count for goal Ten', type: 'int', minValue: 0, default: 0, required: false }, { name: 'goalDescriptionTen', label: 'Description for goal Ten', type: 'str', minLength: 1, maxLength: 255, required: false } ]; cb.onTip(function(tip) { totalTippedTokens += tip['amount']; if (totalTippedTokens > getRequiredTokens) totalTippedTokens = getRequiredTokens; lastTipperName = tip['from_user']; lastTipperTokens = tip['amount']; if (tip['amount'] > highestTipperTokens) { highestTipperName = tip['from_user']; highestTipperTokens = tip['amount']; }; updateSubject(); cb.drawPanel(); }); cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Tokens Received / Goal:', 'row1_value': '' + totalTippedTokens + ' / ' + getRequiredTokens(), 'row2_label': 'Highest Tip:', 'row2_value': formatUsername(highestTipperName) + ' (' + highestTipperTokens + ')', 'row3_label': 'Latest Tip Received:', 'row3_value': formatUsername(lastTipperName) + ' (' + lastTipperTokens + ')' }; }); cb.onMessage(function (msg) { var noticeString = 'Active Goal: ' + activeGoal + '>' + getGoalDescription(activeGoal) + '\n\n' + 'Goals during this show:'; if (msg['m'] == '!goals') { for (var i = 0; i < cb.settings.tipGoalCount; i++) { noticeString += '\n ' + i + '> ' + getGoalDescription(i + 1); }; msg['X-Spam'] = true; cb.sendNotice(noticeString, msg['user']); }; return msg; }); // Functions function updateSubject() { if (getRemainingTokens() == 0) { if (lastGoalReached) return; if (activeGoal == cb.settings.tipGoalCount) { lastGoalReached = true; } else { lastGoalReached = false; totalTippedTokens = 0; activeGoal++; }; } else { lastGoalReached = false; }; var newSubject = cb.settings.subjectPrefix + ' - ' + getGoalDescription(activeGoal) + ' [' + getRemainingTokens() + ' tokens remaining]'; cb.log("Changing subject to: " + newSubject); cb.changeRoomSubject(newSubject); } function getRemainingTokens() { var remaining = getRequiredTokens() - totalTippedTokens; if (remaining < 0) { return 0; } else { return remaining; }; } function formatUsername(val) { if (val === '') { return "--"; } else { return val.substring(0, 12); }; } function getRequiredTokens() { if (activeGoal == 1) return cb.settings.tokensOne; if (activeGoal == 2) return cb.settings.tokensTwo; if (activeGoal == 3) return cb.settings.tokensThree; if (activeGoal == 4) return cb.settings.tokensFour; if (activeGoal == 5) return cb.settings.tokensFive; if (activeGoal == 6) return cb.settings.tokensSix; if (activeGoal == 7) return cb.settings.tokensSeven; if (activeGoal == 8) return cb.settings.tokensEight; if (activeGoal == 9) return cb.settings.tokensNine; if (activeGoal == 10) return cb.settings.tokensTen; } function getGoalDescription(goalId) { if (goalId == 1) return cb.settings.goalDescriptionOne; if (goalId == 2) return cb.settings.goalDescriptionTwo; if (goalId == 3) return cb.settings.goalDescriptionThree; if (goalId == 4) return cb.settings.goalDescriptionFour; if (goalId == 5) return cb.settings.goalDescriptionFive; if (goalId == 6) return cb.settings.goalDescriptionSix; if (goalId == 7) return cb.settings.goalDescriptionSeven; if (goalId == 8) return cb.settings.goalDescriptionEight; if (goalId == 9) return cb.settings.goalDescriptionNine; if (goalId == 10) return cb.settings.goalDescriptionTen; } function getGoalText() { if (activeGoal == cb.settings.tipGoalCount) { return 'Last Goal'; } else { switch (activeGoal) { case 1: return 'One'; case 2: return 'Two'; case 3: return 'Three'; case 4: return 'Four'; case 5: return 'Five'; case 6: return 'Six'; case 7: return 'Seven'; case 8: return 'Eight'; case 9: return 'Nine'; case 10: return 'Ten'; }; }; } function writeInfo() { cb.chatNotice("Type !goals to see the goal information"); cb.setTimeout(writeInfo, timerInterval); } function initApp() { updateSubject(); writeInfo(); cb.setTimeout(writeInfo, timerInterval); } // Initializer initApp();
© Copyright Freesexcam 2011- 2024. All Rights Reserved.