Apps Home
|
Create an App
tip goal autoadjusted
Author:
papapa
Description
Source Code
Launch App
Current Users
Created by:
Papapa
// vars var total_tipped = 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 counter=0; var total = 0; var tempo = new Array; var temp=0; var contador=0; var valor=0; confirmacion=0; cb.settings_choices = [ {name: 'tokens', type: 'int', minValue: 1, default: 100}, {name: 'goal_description', type: 'str', minLength: 1, maxLength: 255} ]; // handlers cb.onTip(function(tip) { total_tipped += tip['amount'] total += tip['amount'] if (total_tipped > cb.settings.tokens) { total_tipped = cb.settings.tokens; } 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'] } cb.drawPanel(); }); cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Tip Received / Goal :', 'row1_value': '' + total_tipped + ' / ' + cb.settings.tokens, '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; } var new_subject = cb.settings.goal_description + " [" + tips_remaining() + " tokens remaining]"; cb.log("Changing subject to: " + new_subject); cb.changeRoomSubject(new_subject); } function tips_remaining() { var r = cb.settings.tokens - total_tipped; if (r < 0) { return 0; } else { return r; } } function format_username(val) { if (val === null) { return "--"; } else { return val.substring(0, 12); } } cb.onLeave(function(room_slug) { confirmacion=1; cb.cancelTimeout(time); }); cb.onEnter(function(room_slug) { confirmacion=0; time=cb.setTimeout(automatic, 60000); }); function automatic() { counter++; tempo[counter]= new Array; var msg=''; tempo[0]=0; if(counter>1)tempo[counter-1]=total; if(counter>1 && confirmacion==0){ for(var i=0; i<counter; i++){ msg +="Tempo[" + i + "]" + tempo[i] + "\n"; if(tempo[i]!=0){ contador++; valor += tempo[i]; } } msg +="confirmacion es " + confirmacion + "valor " + valor + "contador " + contador; cb.settings.tokens = parseInt(valor/contador*6); } if(confirmacion==0)contador=0; if(confirmacion==0)valor=0; //if(counter>1 && total_tipped!=cb.settings.tokens){ //if(tempo[counter-1]/tempo.leght>=tempo[counter-2]/(tempo.leght)){ /* temp=cb.settings.tokens; if(total<parseInt(cb.settings.tokens/6) && total_tipped<parseInt(cb.settings.tokens*0.8)){ msg +="temp " + temp; if(total>10){ cb.settings.tokens = total*6; } else{ cb.settings.tokens = 60; msg +="The goal doesn't word, you earned less than 10tks in the last 10 min \n"; } msg +="Good News: The goal has been decreased"; } } else { // if(temp!=0 && temp>total_tipped) msg +="temp " + temp; cb.settings.tokens = temp; } } msg +="Total es " + total; */ cb.sendNotice(msg, '', '#FFF0DE', '#8A4900', 'bold'); total=0; cb.drawPanel(); } function init() { update_subject(); var time=cb.setTimeout(automatic, 60000); } init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.