Apps Home
|
Create an App
Goal Roulette
Author:
emi0x29a
Description
Source Code
Launch App
Current Users
Created by:
Emi0x29a
// Title: Goal Roulette // Author: emi0x29a // Version: 0.1 (26.09.2015) 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 goals = []; var c_goal = null; cb.settings_choices = [ {name: 'tokens', type: 'int', minValue: 1, default: 100}, {name: 'shot_price', type: 'int', minValue: 1, default: 20}, {name: 'goal_description', type: 'str', minLength: 1, maxLength: 255}, {name: 'goal_1', type: 'str', minLength: 1, maxLength: 255}, {name: 'goal_2', type: 'str', minLength: 1, maxLength: 255}, {name: 'goal_3', type: 'str', minLength: 1, maxLength: 255, required: false}, {name: 'goal_4', type: 'str', minLength: 1, maxLength: 255, required: false}, {name: 'goal_5', type: 'str', minLength: 1, maxLength: 255, required: false}, ]; cb.onTip(function(tip) { total_tipped += 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) { if(last_tip_amount == cb.settings.shot_price){ cb.sendNotice("Goal Changed!"); c_goal = goals[Math.floor(Math.random() * goals.length)]; } return { 'template': '3_rows_of_labels', 'row1_label': 'Tip Received / Goal :', 'row1_value': '' + total_tipped + ' / ' + cb.settings.tokens, 'row2_label': 'Current Goal:', 'row2_value': c_goal, 'row3_label': 'Shot Price:', 'row3_value': cb.settings.shot_price }; }); cb.onMessage(function (msg) { if (msg['m'].match(/\/goals/i)) { msg['X-Spam'] = true; if (msg['m'].match(/all/i) && ((msg['is_mod'] == true) || (msg['user'] == cb.room_slug))) { showGoals(); } else { showGoals2(msg['user']); } } return msg; }); 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); } } function showGoals2(username) { var msg = "Possible Goals:"; for (var i = 0; i < goals.length ; i++) { msg += "\n- "+ goals[i]; } cb.sendNotice(msg,username); } function showGoals() { var msg = "Possible Goals:"; for (var i = 0; i < goals.length ; i++) { msg += "\n- "+ goals[i]; } cb.sendNotice(msg); } function show() { var msg = "Welcome to the Goal Roulette.\n Type /goals to list all the possible goals.Type \"/goals all\" to send the list to all viewers if you're a mod or the broadcaster."; cb.sendNotice(msg); } function init() { goals.push(cb.settings.goal_1,cb.settings.goal_2); c_goal = goals[0]; if(cb.settings.goal_3){ goals.push(cb.settings.goal_3); } if(cb.settings.goal_4){ goals.push(cb.settings.goal_4); } if(cb.settings.goal_5){ goals.push(cb.settings.goal_5); } update_subject(); show(); } init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.