Apps Home
|
Create an App
Be My Valentine
Author:
jessica_shine
Description
Source Code
Launch App
Current Users
Created by:
Jessica_Shine
var total_tipped = 0; var startup_time = new Date(); var scores = { _data:[], _last_valentine:null, increment:function (username, amount) { var score = scores._pop_user(username); score += amount; scores._insert_score_keeping_sort(username, score); scores._check_for_valentine_change(); }, is_user_valentine:function (username) { return scores._last_valentine == username; }, _check_for_valentine_change:function () { if (scores._data.length == 0) { if (scores._last_valentine != null && cb.settings.remove_valentine_when == 'score decays to 0') { cb.chatNotice(scores._last_valentine + " is no longer the valentine."); scores._last_valentine = null; } return; } var valentine = scores._data[0].username; if (valentine != scores._last_valentine) { if (scores._data[0].score >= cb.settings.tokens_per_minute_to_be_valentine) { cb.chatNotice(valentine + " is the new valentine."); scores._last_valentine = valentine; return; } } if (scores._last_valentine != null && cb.settings.remove_valentine_when == 'score decays to 0' && scores.score_for(scores._last_valentine) == 0) { cb.chatNotice(scores._last_valentine + " is no longer the valentine."); scores._last_valentine = null; return; } }, score_for:function (username) { for (var i = 0; i < scores._data.length; i++) { if (scores._data[i].username == username) { return scores._data[i].score; } } return 0; }, get_current_valentine:function () { return scores._last_valentine; }, _insert_score_keeping_sort:function (username, score) { var row = {score:score, username:username}; for (var i = 0; i < scores._data.length; i++) { if (score > scores._data[i].score) { scores._data.splice(i, 0, row); return; } } scores._data.push(row); }, _pop_user:function (username) { for (var i = 0; i < scores._data.length; i++) { if (scores._data[i].username == username) { var s = scores._data[i]; scores._data.splice(i, 1); return s.score; } } return 0; }, send_stats:function (to_user) { cb.chatNotice("== Be My Valentine Scores (Top 10) ==", to_user); var len = scores._data.length; if (len > 10) { len = 10; } for (var i = 0; i < len; i++) { cb.chatNotice(scores._data[i].username + ": (" + Math.ceil(scores._data[i].score) + " pts)", to_user); } if (len == 0) { cb.chatNotice("Nobody has any points. Send tips to get points.", to_user); } else { cb.chatNotice("All scores decay " + cb.settings.tokens_per_minute_to_be_valentine + " every minute.", to_user); } var seconds_running = ((new Date()).getTime() - startup_time.getTime()) / 1000; if (seconds_running == 0) { seconds_running = 1; } cb.chatNotice("Be My Valentine has been running for " + Math.round(seconds_running / 36)/100 + " hours and has counted " + total_tipped + " tokens.", to_user); cb.chatNotice("Valentines will remain until " + cb.settings.remove_valentine_when + ".", to_user); }, decay:function () { var decay_amount = cb.settings.tokens_per_minute_to_be_valentine / 6; for (var i = 0; i < scores._data.length; i++) { scores._data[i].score -= decay_amount; if (scores._data[i].score <= 0) { scores._data.splice(i, 1); } } scores.schedule_decay(); scores._check_for_valentine_change(); cb.drawPanel(); }, schedule_decay:function () { setTimeout(scores.decay, 10000); } }; scores.schedule_decay(); // Chaturbate hooks cb.settings_choices = [ {name:'tokens_per_minute_to_be_valentine', type:'int', minValue:1, maxValue:99, default:5}, {name:'remove_valentine_when', type:'choice', choice1:'someone else outbids', choice2:'score decays to 0', default:5} ]; cb.onDrawPanel(function (user) { var valentine = scores.get_current_valentine(); if (user == cb.room_slug) { if (valentine == null) { var valentinestr = "--"; } else { var valentinestr = valentine + " (" + Math.ceil(scores.score_for(valentine)) + " pts)" } return { 'template':'3_rows_12_22_31', 'row1_label':'Be My Valentine:', 'row1_value':valentinestr, 'row2_label':'Total Tokens Earned:', 'row2_value':"" + total_tipped + ' Tokens', 'row3_value':'Type /stats for more information.' }; } else if (user == valentine) { var lead = scores.score_for(user); if (scores._data.length >= 2) { lead -= scores._data[1].score; } return { 'template':'3_rows_11_21_31', 'row1_value':'Welcome to Be My Valentine!', 'row2_value':'You Are Valentine! Lead: ' + Math.ceil(lead) + ' Tokens', 'row3_value':'Type /stats for more information.' }; } else { var tip_required = cb.settings.tokens_per_minute_to_be_valentine; if (valentine != null) { var valentinescore = scores.score_for(valentine); if (valentinescore >= tip_required) { tip_required = valentinescore + 1; } } tip_required -= scores.score_for(user); return { 'template':'3_rows_11_21_31', 'row1_value':'Welcome to Be My Valentine!', 'row2_value':'Tip required to become valentine: ' + Math.ceil(tip_required) + ' Tokens', 'row3_value':'Type /stats for more information.' }; } }); cb.onTip(function (tip) { scores.increment(tip['from_user'], parseInt(tip['amount'])); total_tipped += parseInt(tip['amount']) cb.drawPanel(); }); cb.onMessage(function (msg) { if (scores.is_user_valentine(msg['user'])) { msg['background'] = '#f9c'; } if (msg['m'] == '/stats') { msg['X-Spam'] = true; scores.send_stats(msg['user']); } return msg; });
© Copyright Freesexcam 2011- 2024. All Rights Reserved.