Apps Home
|
My Uploads
|
Create an App
TipGoal test
Author:
merijnh
Description
Source Code
Launch App
Current Users
Created by:
Merijnh
App Images
// vars var backgroundImageNormal = '6d615087-af90-4803-9b22-40a9caa52a26'; var backgroundImageReached = '6b845fba-b411-42c5-8494-1b6b60eb3162'; //test var backgroundImageNormal = 'b4a4ea3d-969b-4ab4-91d1-bea1f0d87eb2'; var backgroundImageReached = '68f055ad-0732-4411-b9ad-ce0bccab076e'; var total_tokens_tipped = 0; var tokens_tipped = 0; var times_reached = 0; var high_tip_username = null; var high_tip_amount = 0; var last_tip_username = null; var last_tip_amount = 0; var subject_is_set_with_0 = false; var goal_reached = false; var backgroundImage = backgroundImageNormal; var Layer1Label = ''; var Layer1Text = ''; var newgoal = 0; var timesreached = 0; cb.settings_choices = [ { name: 'multi_goal', label: 'Use Multi Goal', type: 'choice', choice1: 'No', choice2: 'Yes', defaultValue: 'No' }, { name: 'tokens', type: 'int', minValue: 1, defaultValue: 970 }, { name: 'goal_description', label: 'Goal description / room subject', type: 'str', minLength: 1, maxLength: 255 }, { name: 'change_room_subject', label: 'Change room subject on tip', type: 'choice', choice1: 'No', choice2: 'Yes', defaultValue: 'No' }, { name: 'panel_style', label: 'Panel style', type: 'choice', choice1: 'New style', choice2: 'Old style', defaultValue: 'New style' }, { name: 'noticeTime', label: 'Remaining tokens notice interval (minutes)', type: 'str', minLength: 1, maxLength: 255, defaultValue: 2 } ]; // handlers cb.onTip(function(tip) { total_tokens_tipped += tip['amount'] tokens_tipped += tip['amount'] if(goal_reached == false) { Layer1Text = '' + total_tokens_tipped - cb.settings.tokens*times_reached + " / " + cb.settings.tokens; } if (total_tokens_tipped - cb.settings.tokens*times_reached >= cb.settings.tokens && goal_reached == false) { goal_reached = true; // times reached timesreached = Math.floor((total_tokens_tipped - cb.settings.tokens*times_reached) / cb.settings.tokens); times_reached = times_reached + timesreached; newgoal = times_reached + 1; var i = timesreached; cb.sendNotice(":goallll", '', '', '#000000', 'bolder'); do { i = i - 1; var a = times_reached - i; cb.sendNotice('Goal #' + a + ' reached!! Thanks to all tippers!', '', '', '#000000', 'bolder'); } while (i > 0); if(cb.settings.multi_goal == "No"){ Layer1Label = ''; Layer1Text = ''; backgroundImage = backgroundImageReached; } else { tokens_tipped = 0; Layer1Label = 'Goal #' + newgoal + ''; Layer1Text = "" + total_tokens_tipped - cb.settings.tokens*times_reached + " / " + cb.settings.tokens + ""; } } if(cb.settings.multi_goal == "No"){ if (tokens_tipped > cb.settings.tokens) { tokens_tipped = cb.settings.tokens; } } else { goal_reached = false; } if(cb.settings.multi_goal == "Yes" && times_reached >= 1){ Layer1Text = Layer1Text + " (" + total_tokens_tipped + ")"; } if (cb.settings.change_room_subject == 'Yes') { update_subject(); } last_tip_amount = tip['amount'] last_tip_username = tip['from_user'] if (tip['amount'] > high_tip_amount) { high_tip_amount = tip['amount'] high_tip_username = tip['from_user'] } timesreached = 0; cb.drawPanel(); }); cb.onDrawPanel(function(user) { if (cb.settings.panel_style == 'New style') { return { "template": "image_template", "layers": [{ 'type': 'image', 'fileID': backgroundImage }, { 'type': 'text', 'text': Layer1Label, 'top': 5, 'left': 28, 'font-size': 11, 'color': 'white', }, { 'type': 'text', 'text': 'Highest Tip', 'top': 28, 'left': 68, 'font-size': 11, 'color': 'white', }, { 'type': 'text', 'text': 'Latest Tip Received', 'top': 51, 'left': 28, 'font-size': 11, 'color': 'white', }, { 'type': 'text', 'text': Layer1Text, 'top': 5, 'left': 147, 'font-size': 11, 'color': 'white', }, { 'type': 'text', 'text': format_username(high_tip_username) + ' (' + high_tip_amount + ')', 'top': 28, 'left': 147, 'font-size': 11, 'color': 'white', }, { 'type': 'text', 'text': format_username(last_tip_username) + ' (' + last_tip_amount + ')', 'top': 51, 'left': 147, 'font-size': 11, 'color': 'white', }, ], }; } else { return { 'template': '3_rows_of_labels', 'row1_label': Layer1Label, 'row1_value': Layer1Text, 'row2_label': 'Highest Tip:', 'row2_value': format_username(high_tip_username) + ' (' + high_tip_amount + ')', 'row3_label': 'Latest Tip Received:', 'row3_value': format_username(last_tip_username) + ' (' + last_tip_amount + ')' }; } }); // helper functions function update_subject() { if (tips_remaining() == 0) { if (subject_is_set_with_0) { return; } subject_is_set_with_0 = true; } else { subject_is_set_with_0 = false; } if (cb.settings.change_room_subject == 'Yes') { var new_subject = cb.settings.goal_description + " [" + tips_remaining() + " tokens remaining]"; } else { var new_subject = cb.settings.goal_description; } cb.log("Changing subject to: " + new_subject); cb.changeRoomSubject(new_subject); } function tips_remaining() { var r = cb.settings.tokens - (total_tokens_tipped - cb.settings.tokens*times_reached); if (r < 0) { return 0; } else { return r; } } function format_username(val) { if (val === null) { return "--"; } else { return val.substring(0, 12); } } function ShowRemaining() { if (!goal_reached) { cb.sendNotice('' + tips_remaining() + ' tokens remaining for goal', '', '', '#000000', 'bolder'); cb.setTimeout(ShowRemaining, cb.settings.noticeTime * 60000); } } function init() { if(cb.settings.multi_goal == "Yes"){ newgoal = 1; Layer1Label = 'Goal #' + newgoal + ''; }else{ Layer1Label = 'Tip Received / Goal'; } Layer1Text = '' + tokens_tipped + ' / ' + cb.settings.tokens; ShowRemaining(); update_subject(); } init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.