Apps Home
|
My Uploads
|
Create an App
moloh_test1
Author:
molohlove
Description
Source Code
Launch App
Current Users
Created by:
Molohlove
App Images
cb.settings_choices = [ {label:'Guest level', name: 'status_0', type: 'str', minLength: 1, maxLength: 255, default: 'Guest'}, {label:'Level 1', name: 'status_1', type: 'str', minLength: 1, maxLength: 255, default: 'Private'}, {label:'Level 2', name: 'status_2', type: 'str', minLength: 1, maxLength: 255, default: 'Major'}, {label:'Level 3', name: 'status_3', type: 'str', minLength: 1, maxLength: 255, default: 'Colonel'}, {label:'Level 4', name: 'status_4', type: 'str', minLength: 1, maxLength: 255, default: 'General'}, {label:'Level 5', name: 'status_5', type: 'str', minLength: 1, maxLength: 255, default: 'President'}, {label:'Level 1 Min Val', name: 'status_1_min_val', type: 'int', minValue: 1, default: 20}, {label:'Level 2 Min Val', name: 'status_2_min_val', type: 'int', minValue: 1, default: 40}, {label:'Level 3 Min Val', name: 'status_3_min_val', type: 'int', minValue: 1, default: 60}, {label:'Level 4 Min Val', name: 'status_4_min_val', type: 'int', minValue: 1, default: 80}, {label:'Level 5 Min Val', name: 'status_5_min_val', type: 'int', minValue: 1, default: 100}, {label:'The total tokens', name: 'tokens', type: 'int', minValue: 1, default: 100} ]; var startPerMin, stopPerMin, nextStatus, kName; var kTip = 0; var kName = ''; var intervalsArr = new Object(); var tippersArr = new Object(); for(var i = 0; i <= 5; i++) { nextStatus = i + 1; if(cb.settings['status_'+i+'_min_val']) startPerMin = (cb.settings['status_'+i+'_min_val'] / 60).toFixed(2); stopPerMin = (cb.settings['status_'+nextStatus+'_min_val'] / 60).toFixed(2); if(i == 0) intervalsArr[0] = {start:0, stop:cb.settings['status_'+nextStatus+'_min_val'], start_per_min: 0, stop_per_min:stopPerMin}; else intervalsArr[i] = {start:cb.settings['status_'+i+'_min_val'], stop:cb.settings['status_'+nextStatus+'_min_val'], start_per_min: startPerMin, stop_per_min:stopPerMin}; } intervalsArr[5]['stop'] = 10000000; intervalsArr[5]['stop_per_min'] = (intervalsArr[5]['stop'] / 60).toFixed(2); cb.chatNotice(' intervalsArr = ' + JSON.stringify(tippersArr)); //cb.chatNotice('There can be only ONE. To become '+cb.settings['status_5']); cb.onTip(function (tip) { var attackVal = 0; Object.keys(tippersArr).forEach(function (userName, arr) { if(tip['message'].indexOf(userName) !== -1){ //cb.chatNotice('attac'); attackVal = 1; attack1(tip, userName); } }); if(attackVal == 0) update_user(tip); }); cb.onMessage(function (msg) { if (msg['user'] == cb.room_slug && msg['m'].match(/\/prizes/i)) { cb.chatNotice("sunt broadcasterul", cb.room_slug); } }); function update_user(tip) { var newKing = 0; var currentStatus = 0; var currentStatusName = 'status_'+currentStatus; var statusMinVal; var nextStatus; var nextStatusName; var nextStatusMinVal; var timeDiff; var tipPerMin; var tipTime = new Date(); var cbNoticeToBecomeKing = 0; var kTipPerMin = 0; if(typeof tippersArr[tip['from_user']] === 'undefined' || !tippersArr[tip['from_user']]) { tippersArr[tip['from_user']] = new Object(); tippersArr[tip['from_user']] = {first_tip_time: tipTime, total_tipped: tip['amount'], status_name: cb.settings[currentStatusName], status: currentStatus}; } else tippersArr[tip['from_user']]['total_tipped'] += tip['amount']; timeDiff = ( (tipTime - tippersArr[tip['from_user']]['first_tip_time']) / (1000 * 60) ).toFixed(2); //timeDiff = 78; for(var i = 0; i <= 5; i++) { if(timeDiff >= 0 && timeDiff <= 60) { if( (intervalsArr[i]['start'] < tippersArr[tip['from_user']]['total_tipped'] && tippersArr[tip['from_user']]['total_tipped'] <= intervalsArr[i]['stop']) ){ currentStatus = i; if(currentStatus == 5) { if(tippersArr[tip['from_user']]['total_tipped'] > kTip && kName != tip['from_user']) newKing = 1; else { cbNoticeToBecomeKing = 1; currentStatus = 4; } } else { if(tippersArr[tip['from_user']]['status'] != currentStatus) cb.chatNotice('Your new status is '+cb.settings['status_'+currentStatus]+'. Congratulations!', tip['from_user']); else { var possibleStatusName = currentStatus + 1; var nextPossibleStatus = cb.settings['status_'+possibleStatusName]; var tipDiffToNextStatus = intervalsArr[currentStatus]['stop'] - tippersArr[tip['from_user']]['total_tipped'] + 1; cb.chatNotice('You are still '+cb.settings['status_'+currentStatus]+'. To claim glory and become '+nextPossibleStatus+' you must tip at least '+tipDiffToNextStatus+' tokens.', tip['from_user']); } } } } else { tipPerMin = (tippersArr[tip['from_user']]['total_tipped'] / timeDiff).toFixed(2); if( (intervalsArr[i]['start_per_min'] < tipPerMin && tipPerMin <= intervalsArr[i]['stop_per_min']) ) { currentStatus = i; if(currentStatus == 5) { //if(tipPerMin > kTipPerMin) newKing = 1; if(tippersArr[tip['from_user']]['total_tipped'] > kTip && kName != tip['from_user']) newKing = 1; else { cbNoticeToBecomeKing = 1; currentStatus = 4; } } else { if(tippersArr[tip['from_user']]['status'] != currentStatus) cb.chatNotice('Your new status is '+cb.settings['status_'+currentStatus]+'. Congratulations!', tip['from_user']); else { var possibleStatusName = currentStatus + 1; var nextPossibleStatus = cb.settings['status_'+possibleStatusName]; var tipDiffToNextStatus = ((intervalsArr[currentStatus]['stop_per_min'] - tipPerMin + 0.01) * timeDiff).toFixed(0); cb.chatNotice(tipDiffToNextStatus); cb.chatNotice('You are still '+cb.settings['status_'+currentStatus]+'. To claim glory and become '+nextPossibleStatus+' you must tip at least '+tipDiffToNextStatus+' tokens.', tip['from_user']); } } } } } var oldKingKey = get_old_king(); var demotedKing = 0; if(newKing == 1) { kTip = tippersArr[tip['from_user']]['total_tipped']; //kTipPerMin = (kTip / timeDiff).toFixed(2); kName = tip['from_user']; if(oldKingKey != '' && oldKingKey != kName) { tippersArr[oldKingKey]['status'] = 4; tippersArr[oldKingKey]['status_name'] = 'status_4'; demotedKing = 1; } } currentStatusName = 'status_'+currentStatus; tippersArr[tip['from_user']]['status_name'] = currentStatusName; tippersArr[tip['from_user']]['status'] = currentStatus; if(cbNoticeToBecomeKing == 1 && demotedKing == 0) { var tipDiffToBeKing = tippersArr[oldKingKey]['total_tipped'] - tippersArr[tip['from_user']]['total_tipped'] + 1; cb.chatNotice('There can be only ONE. To become '+cb.settings['status_5']+' you must tip an extra '+tipDiffToBeKing+' tokens.', tip['from_user']); } if(newKing == 1) { cb.chatNotice('CONGRATULATIONS!!! You are now '+cb.settings['status_5']+'.', tip['from_user']); cb.chatNotice('The new '+cb.settings['status_5']+' of the room is '+tip['from_user']+'! Hooray for the great '+tip['from_user']); } if(demotedKing == 1) { var tipDiffToBeKing = tippersArr[tip['from_user']]['total_tipped'] - tippersArr[oldKingKey]['total_tipped'] + 1; cb.chatNotice('Your status as '+cb.settings['status_5']+' was taken by '+tip['from_user']+'! To reclaim your HONOR you must tip at least '+tipDiffToBeKing+' tokens!', oldKingKey); } //cb.chatNotice(' tippersArr = ' + JSON.stringify(tippersArr)); } function update_users() { var now = new Date(); //var now1 = new Date(now.getTime() + 65*60000); var now1 = new Date(); /* cb.chatNotice(now); cb.chatNotice(now1); cb.chatNotice('update_users'); /**/ var timeDiff; var currentStatus; var tipPerMin; Object.keys(tippersArr).forEach(function (userName, arr) { timeDiff = ( (now1 - tippersArr[userName]['first_tip_time']) / (1000 * 60) ).toFixed(2); tipPerMin = (tippersArr[userName]['total_tipped'] / timeDiff).toFixed(2); //cb.chatNotice('timeDiff='+timeDiff+' tipPerMin='+tipPerMin); for(var i = 0; i <= 5; i++) { if( (intervalsArr[i]['start_per_min'] < tipPerMin && tipPerMin <= intervalsArr[i]['stop_per_min']) ) { currentStatus = i; if(tippersArr[userName]['status'] != currentStatus && currentStatus != 5) { var oldStatus = tippersArr[userName]['status']; var nextPossibleStatus = cb.settings['status_'+possibleStatusName]; if(typeof intervalsArr[possibleStatusName]['start_per_min'] === 'undefined' || !intervalsArr[possibleStatusName]['start_per_min']) { var tipDiffToNextStatus = ((intervalsArr[possibleStatusName]['start_per_min'] - tipPerMin + 0.01) * timeDiff).toFixed(0); //cb.chatNotice('currentStatus='+currentStatus+' oldStatus='+oldStatus+' possibleStatusName='+possibleStatusName+' nextPossibleStatus='+nextPossibleStatus+' tipDiffToNextStatus='+tipDiffToNextStatus); cb.chatNotice('Your lost '+cb.settings['status_'+oldStatus]+' and were downgraded to '+cb.settings['status_'+currentStatus]+'. To regain your honor as '+cb.settings['status_'+oldStatus]+' status you can tip '+tipDiffToNextStatus+' tokens!', userName); currentStatusName = 'status_'+currentStatus; tippersArr[userName]['status_name'] = currentStatusName; tippersArr[userName]['status'] = currentStatus; } } //cb.chatNotice(' tippersArr = ' + JSON.stringify(tippersArr)); } } }); cb.setTimeout(update_users, 6000); //cb.setTimeout(update_users, 60000); } function get_old_king(){ var oldKingKey = ''; Object.keys(tippersArr).forEach(function (key, arr) { if(tippersArr[key]['status'] == 5) oldKingKey = key; }); return oldKingKey; } cb.setTimeout(update_users, 360000); function attack1(tip1, userName) { var attackerName = tip1['from_user']; var attackForce = tip1['amount']; tip1['from_user'] = userName; tip1['amount'] = 0 - tip1['amount']; var oldStatus = tippersArr[userName]['status']; update_user(tip1); var newStatus = tippersArr[userName]['status']; if(oldStatus != newStatus){ cb.chatNotice('You were attacked by '+attackerName+' with a '+attackForce+' tokens hit and downgraded you from '+cb.settings['status_'+oldStatus]+' to '+cb.settings['status_'+newStatus]+'. Will you let this stand?!!!' , userName); cb.chatNotice('Wow, you struck a great blow to '+userName+'. You managed to downgrade him from '+cb.settings['status_'+oldStatus]+' to '+cb.settings['status_'+newStatus]+'!' , attackerName); } else { cb.chatNotice('You were attacked by '+attackerName+' with a '+attackForce+' tokens hit, but you managed to keep your '+cb.settings['status_'+oldStatus]+' status. However, attack tokens will be drawn from your purse. Will you let this stand?!! ', userName); cb.chatNotice("Your brave attack didn't damage "+userName+"'s status but you did take the attack value from his purse. Next attack might cripple him!", attackerName); } }
© Copyright Chaturbate 2011- 2025. All Rights Reserved.