Apps Home
|
Create an App
Tip Jar plus Goals by lol_laptop
Author:
rhend99
Description
Source Code
Launch App
Current Users
Created by:
Rhend99
/* Author: Lol_Laptop Description: Tip jar plus goals Comments, questions, bug reports? Message me on Twitter @lol_laptop Commands: /pause - Pause the tip jar /resume - Resume the tip jar /setjar - Manually set the tip jar to contain tokens /drainrate - Adjust how often tokens are drained, in seconds (decimal values are accepted) /drainvalue - Adjust how many tokens are drained /startat - Adjust the value at which tokens begin draining from the tip jar /goals - Shows current list of goals /setgoal - Adjust the progress towards the current goal /addgoal- Manually add a goal /removegoal - Remove a goal (use the ID specified in /goals) */ cb.settings_choices = [ {name: 'subject_header', label: 'Subject header', type: 'str', minLength: 1, maxLength: 255, defaultValue: 'Keep the tip jar full, and meet my goals!'}, {name:'broadcaster_notification', label: 'Addtional broadcaster notification when goals met/tip jar active', type:'choice', choice1:'Yes', choice2:'No', defaultValue:'Yes'}, {name:'jarStart', type:'int', minValue:0, defaultValue:50, label: "Jar begins draining at"}, {name:'jarDrainRate', type:'int', minValue:0, defaultValue:1, label: "How often the jar drains (seconds)"}, {name:'jarDrainValue', type:'int', minValue:0, defaultValue:1, label: "Tokens to drain per tick"}, {name: 'finality_message', label: 'Final Goal Met Subject', type: 'str', minLength: 1, maxLength: 255, defaultValue: 'Goal reached! Thanks to all tippers!'}, {name:'goalTarget1', label: 'Goal 1 Target', type:'int', minValue:1, defaultValue: 200}, {name:'goalDesc1', label:'Goal 1 Description', type:'str', minLength: 1, maxLength: 255}, {name:'goalTarget2', label: 'Goal 2 Target', type:'int', minValue:1, defaultValue: 200, required: false}, {name:'goalDesc2', label:'Goal 2 Description', type:'str', minLength: 1, maxLength: 255, required: false}, {name:'goalTarget3', label: 'Goal 3 Target', type:'int', minValue:1, defaultValue: 200, required: false}, {name:'goalDesc3', label:'Goal 3 Description', type:'str', minLength: 1, maxLength: 255, required: false}, {name:'goalTarget4', label: 'Goal 4 Target', type:'int', minValue:1, defaultValue: 200, required: false}, {name:'goalDesc4', label:'Goal 4 Description', type:'str', minLength: 1, maxLength: 255, required: false}, {name:'goalTarget5', label: 'Goal 5 Target', type:'int', minValue:1, defaultValue: 200, required: false}, {name:'goalDesc5', label:'Goal 5 Description', type:'str', minLength: 1, maxLength: 255, required: false}, {name:'goalTarget6', label: 'Goal 6 Target', type:'int', minValue:1, defaultValue: 200, required: false}, {name:'goalDesc6', label:'Goal 6 Description', type:'str', minLength: 1, maxLength: 255, required: false}, {name:'goalTarget7', label: 'Goal 7 Target', type:'int', minValue:1, defaultValue: 200, required: false}, {name:'goalDesc7', label:'Goal 7 Description', type:'str', minLength: 1, maxLength: 255, required: false}, {name:'goalTarget8', label: 'Goal 8 Target', type:'int', minValue:1, defaultValue: 200, required: false}, {name:'goalDesc8', label:'Goal 8 Description', type:'str', minLength: 1, maxLength: 255, required: false} ]; //var bn = (cb.settings.broadcaster_notication == "Yes"); var jarStart = cb.settings.jarStart; //Value to start draining at var jarDrainRate = cb.settings.jarDrainRate; // How often the jar drains (seconds) var jarDrainValue = cb.settings.jarDrainValue; //How many tokens are drained var jarDrainValue2 = jarDrainValue; var jarValue = 0; //Current tokens in jar var jarActive = false; var goalsArray = [goal]; //Array of goals var goalCounter = 0; //Current goal var goalValue = 0; //Progress towards goal var goalStart = cb.settings.goalTarget1; var lastSubject = ""; for (var i = 0; i < 8; i++) { var vDesc = eval("cb.settings.goalDesc"+(i+1)); if(eval(vDesc == "")){ break; } var goal = {goal: eval("cb.settings.goalTarget"+(i+1)), goalText: eval("cb.settings.goalDesc"+(i+1)) }; goalsArray[i] = goal; } cb.onTip(function (tip) { jarValue += parseInt(tip['amount']) goalValue += parseInt(tip['amount']) jarTest(); checkGoals(); }); cb.onDrawPanel(function(user) { var vLabel1; var vValue1; if(goalCounter < goalsArray.length) { vLabel1 = "Goal - " + goalsArray[goalCounter].goalText + ':'; vValue1 = goalValue + "/" + goalsArray[goalCounter].goal; } else { vLabel1 = "Final goal reached:"; vValue1 = "Tip Jar still active"; } return { 'template': '3_rows_of_labels', 'row1_label': vLabel1, 'row1_value': vValue1, 'row2_label': 'Tip Jar:', 'row2_value': jarValue +"/" + jarStart, 'row3_label': 'Drain Rate:', 'row3_value': jarDrainValue + " tokens/" + jarDrainRate + " sec." }; }); //commands and junk cb.onMessage(function (msg) { if (msg['user'] == cb.room_slug) { //Only accept commands from the broadcaster msg['X-Spam'] = true; msg['m'] = msg['m'].trim(); var msgArray = msg['m'].split(" "); //Split each word into an array if (msgArray[0].toLowerCase() == '/addgoal') { //add a goal manually if (msgArray.length < 3 || isNaN(Math.abs(parseInt(msgArray[1])))) { alertBroadcaster("Invalid format for goal. Try /addgoal 1000 put a thing in my butt!"); } else { var goalText = ""; for (i = 2; i < msgArray.length; i++) { goalText += msgArray[i] + " "; } var goal = {goal:Math.abs(parseInt(msgArray[1])), goalText:goalText.trim()}; goalsArray[goalsArray.length] = goal; cb.chatNotice('goal "' + goalText.trim() + '" added', cb.room_slug); } checkGoals(); } if (msgArray[0].toLowerCase() == '/removegoal') { //remove a goal if (msgArray.length < 2 || isNaN(Math.abs(parseInt(msgArray[1])) || Math.abs(parseInt(msgArray[1])) < 1)) { alertBroadcaster('Invalid format. Try "/removegoal 1" to remove goal #1'); } else { goalsArray.splice(Math.abs(parseInt(msgArray[1]))-1, 1); if (Math.abs(parseInt(msgArray[1])) < goalCounter) { goalCounter--; } cb.chatNotice('Goal "' + Math.abs(parseInt(msgArray[1])) + '" removed.', cb.room_slug); } checkGoals(); } if (msgArray[0].toLowerCase() == '/pause') { //Pause the tip jar. jarDrainValue2 = jarDrainValue; jarDrainValue = 0; alertBroadcaster("Jar paused."); } if (msgArray[0].toLowerCase() == '/resume') { //Resume the tip jar. jarDrainValue = jarDrainValue2; alertBroadcaster("Jar resumed."); } if (msgArray[0].toLowerCase() == '/reset') { //Reset the tip jar to 0. jarValue = 0; alertBroadcaster("Tip jar reset to 0."); } if (msgArray[0].toLowerCase() == '/setjar') { //Add tokens to the tip jar manually if (msgArray.length < 2 || isNaN(Math.abs(parseInt(msgArray[1])))) { alertBroadcaster('Invalid format. Try "/setjar 100" to have your jar contain 100 tokens.' + parseInt(msgArray[1])); } else { jarValue = parseInt(msgArray[1]); cb.chatNotice(parseInt(msgArray[1]) + ' added to tip jar.', cb.room_slug); jarTest(); } } if (msgArray[0].toLowerCase() == '/setgoal') { //Sets the value for the current goal if (msgArray.length < 2 || isNaN(Math.abs(parseInt(msgArray[1])))) { alertBroadcaster('Invalid format. Try "/setgoal 100" to set your current goal\'s progress to 100 tokens.'); } else { goalValue = Math.abs(parseInt(msgArray[1])); cb.chatNotice(parseInt(msgArray[1]) + ' tokens towards current goal.', cb.room_slug); checkGoals(); } } if (msgArray[0].toLowerCase() == '/drainrate') { //Adjust the drain rate if (msgArray.length < 2 || isNaN(Math.abs(Number(msgArray[1])))) { alertBroadcaster('Invalid format. Try "/drainrate 1.5" to have tokens drain every 1.5 seconds.'); } else { jarDrainRate = Number(msgArray[1]); cb.chatNotice('Drain rate changed to ' + Number(msgArray[1]), cb.room_slug); cb.drawPanel(); } } if (msgArray[0].toLowerCase() == '/drainvalue') { //Adjust the drain value if (msgArray.length < 2 || isNaN(Math.abs(parseInt(msgArray[1])))) { alertBroadcaster('Invalid format. Try "/drainvalue 5" to have tokens drain per tick.'); } else { jarDrainValue = Math.abs(Number(msgArray[1])); cb.chatNotice('Drain value changed to ' + Number(msgArray[1]), cb.room_slug); cb.drawPanel(); } } if (msgArray[0].toLowerCase() == '/startat') { // Set the start value for the jar if (msgArray.length < 2 || isNaN(Math.abs(parseInt(msgArray[1])))) { alertBroadcaster('Invalid format. Try "/startat 100" to have your jar start draining when you reach 100 tokens.' + parseInt(msgArray[1])); } else { jarStart = Math.abs(parseInt(msgArray[1])); cb.chatNotice('Jar will start draining at ' + jarStart + " tokens.", cb.room_slug); jarTest(); } } if (msgArray[0].toLowerCase() == '/goals') { //see current goal list if (goalsArray.length == 0) { cb.chatNotice("No goals added", cb.room_slug); } else { var goalList = ""; for (i = 0; i < goalsArray.length; i++) { goalList += "Goal " + (i + 1) + ": " + goalsArray[i].goalText + " for " + goalsArray[i].goal + " tokens"; if (i != (goalsArray.length - 1)) { goalList += "\n"; } } cb.chatNotice(goalList, cb.room_slug) } } } return msg; }); function updateRoom() { if (goalsArray.length == goalCounter) { cb.changeRoomSubject(cb.settings.finality_message); } else { if (lastSubject != cb.settings.subject_header + " | " + goalsArray[goalCounter].goalText + ": " + (goalStart - goalValue + " remaining")) { cb.changeRoomSubject(cb.settings.subject_header + " | " + goalsArray[goalCounter].goalText + ": " + (goalStart - goalValue) + " remaining"); lastSubject = cb.settings.subject_header + " | " + goalsArray[goalCounter].goalText + ": " + (goalStart - goalValue) + " remaining"; } } cb.drawPanel(); return 0; } function alertBroadcaster(vMessage, vColour){ if (cb.settings.broadcaster_notification == "Yes") { cb.sendNotice(vMessage, cb.room_slug, vColour, "#000000", "bold"); } return } function drainJar() { if (jarValue > 0 && jarActive) { jarValue -= jarDrainValue; cb.setTimeout(drainJar, jarDrainRate*1000); } else { cb.chatNotice("Jar empty!"); alertBroadcaster("JAR EMPTY, STOP", "#FF0000") jarValue = 0; jarActive = false; } cb.drawPanel(); return; } function jarTest() { //cb.chatNotice("Tip jar: " + jarValue); if (jarValue >= jarStart && !jarActive) { jarActive = true; cb.chatNotice("The tip jar draining. Tip to keep it going!"); alertBroadcaster("TIP JAR ACTIVE", "#00AA00"); drainJar(); } updateRoom(); return; } function checkGoals() { goalStart = goalsArray[goalCounter].goal; while (goalValue >= goalStart) { goalValue -= goalStart; cb.chatNotice("Goal reached: " + goalsArray[goalCounter].goalText); alertBroadcaster("GOAL REACHED - " + goalsArray[goalCounter].goalText, "#FF7900"); goalCounter++; goalStart = goalsArray[goalCounter].goal; } updateRoom(); return; } updateRoom();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.