Bots Home
|
Create an App
rollpinkdicetest
Author:
fatkarl33
Description
Source Code
Launch Bot
Current Users
Created by:
Fatkarl33
// FRAME 1.0 // cb.settings_choices cb.settings_choices = []; function add_setting_str(name, label, default_value) { cb.settings_choices.push({ type:"str", name:name, label:label, defaultValue:default_value, required:false }); } function add_setting_int(name, label, default_value, opt_min, opt_max) { var sett = { type:"int", name:name, label:label, defaultValue:default_value }; if (opt_min !== undefined) sett.minValue = opt_min; if (opt_max !== undefined) sett.maxValue = opt_max; cb.settings_choices.push(sett); } function add_setting_choice(name, label, default_value, choices) { var sett = { type:"choice", name:name, label:label, defaultValue:default_value }; for (var i = 0; i < choices.length; i++) sett["choice" + (i + 1)] = choices[i]; cb.settings_choices.push(sett); } function setting(name) { if (cb.settings[name] === undefined) { for (var i = 0; i < cb.settings_choices.length; i++) { if (cb.settings_choices[i].name == name) { if (cb.settings_choices[i].type == "int") return 0; if (cb.settings_choices[i].type == "str") return ""; if (cb.settings_choices[i].type == "choice") return cb.settings_choices[i].defaultValue; } } return ""; } return cb.settings[name]; } function set_setting(name, value) { cb.settings[name] = value; } // callbacks callback_enter_funcs = []; function listen_enter(callback) { callback_enter_funcs.push(callback); } if (cb.onEnter !== undefined) cb.onEnter(function(user) { for (var i = 0; i < callback_enter_funcs.length; i++) callback_enter_funcs[i].apply(this, arguments); }); callback_leave_funcs = []; function listen_leave(callback) { callback_leave_funcs.push(callback); } if (cb.onLeave !== undefined) cb.onLeave(function(user) { for (var i = 0; i < callback_leave_funcs.length; i++) callback_leave_funcs[i].apply(this, arguments); }); callback_message_funcs = []; function listen_message(callback) { callback_message_funcs.push(callback); } if (cb.onMessage !== undefined) cb.onMessage(function(message) { for (var i = 0; i < callback_message_funcs.length; i++) callback_message_funcs[i].apply(this, arguments); }); callback_tip_funcs = []; function listen_tip(callback) { callback_tip_funcs.push(callback); } if (cb.onTip !== undefined) cb.onTip(function(tip) { for (var i = 0; i < callback_tip_funcs.length; i++) callback_tip_funcs[i].apply(this, arguments); }); callback_draw_panel_funcs = []; function listen_draw_panel(callback) { callback_draw_panel_funcs.push(callback); } if (cb.onDrawPanel !== undefined) cb.onDrawPanel(function(user) { for (var i = 0; i < callback_draw_panel_funcs.length; i++) callback_draw_panel_funcs[i].apply(this, arguments); }); // util _notice_color = undefined; function set_notice_color(color) { _notice_color = color; } function notice(msg, user, color, background, weight) { cb.sendNotice(msg, user, background, color == undefined ? _notice_color : color, weight); } function notice_broadcaster(msg) { notice(msg, cb.room_slug, '#CD5C5C'); } function random_int(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } function random_int_except(min, max, except) { var possible = []; for (var i = min; i <= max; i++) { if (i != except) possible.push(i); } return possible[Math.floor(Math.random() * possible.length)]; } function parse_number(s, default_value) { var ss = ""; var palette = "0123456789."; for (var i = 0; i < s.length; i++) { if (palette.indexOf(s[i]) != -1) { ss += s[i]; } } if (ss.length < 1 || isNaN(ss)) return default_value; return parseFloat(ss); } // spam _interval_callback_counter = 0; _interval_callbacks = []; function interval_callback(callback, interval, offset) { if (offset === undefined) offset = 0; _interval_callbacks.push({"callback" : callback, "interval" : interval, "offset" : offset}); } function _check_interval_callback() { for (var i = 0; i < _interval_callbacks.length; i++) { var item = _interval_callbacks[i]; item.offset++; if (item.offset >= item.interval) { item.offset = 0; item.callback(); } } } listen_message(_check_interval_callback); listen_tip(_check_interval_callback); // commands user_types = {broadcaster : 1, moderator : 2, guest : 4, all : 7, staff : 3}; _commands = {}; function add_command(name, argument_count, has_text, permitted_users, callback) { // has_text indicates that command and arguments are followed by plain text if (!(name in _commands)) _commands[name] = []; _commands[name].push({ argument_count:argument_count, has_text:has_text, permitted_users:permitted_users, callback:callback }); } function find_command_handlers(name, argument_count, user_type) { if (!(name in _commands)) return undefined; var handlers = _commands[name]; var found = []; for (var i = 0; i < handlers.length; i++) { if ((!handlers[i].has_text) && handlers[i].argument_count !== argument_count) continue; if (handlers[i].has_text && (handlers[i].argument_count + 1) > argument_count) continue; if ((handlers[i].permitted_users & user_type) === 0) continue; found.push(handlers[i]); } return found; } listen_message(function(msg) { if (msg.m.charAt(0) !== '/') return; // is command var args = msg.m.replace(/\s\s+/g, ' ').split(' '); // standardize and split if (args.length < 1) return; // sanity var command_name = args[0].substring(1).toLowerCase(); // strip slash and lower if (!(command_name in _commands)) return; // at least one callback is registered var user_type = user_types.guest; if (msg.is_mod === true) user_type = user_types.moderator; if (msg.user === cb.room_slug) user_type = user_types.broadcaster; args.splice(0, 1); // args var handlers = find_command_handlers(command_name, args.length, user_type); // find handlers if (handlers.length > 0) msg["X-Spam"] = true; for (var i = 0; i < handlers.length; i++) { var handler = handlers[i]; // execute handlers if (handler.has_text) { var args2 = [msg].concat(args.slice(0, handler.argument_count - 1)); args2.push(args.slice(handler.argument_count).join(" ")); handler.callback.apply(this, args2); } else { handler.callback.apply(this, [msg].concat(args)); } } }); // APP add_setting_str("bot_color", "Bot Color", "#FF1493"); add_setting_int("roll_price", "Price of each roll", 22); add_setting_choice("remove_prizes", "Remove prize when won", "No", ["Yes", "No"]); add_setting_str("game_won_msg", "Message after all prizes have been won", "Game over! No more prizes left."); add_setting_str("prize_lose", "Message on non-winning roll", "but didn't win anything, sorry!"); add_setting_choice("equalize_chances", "Equalize chances (1 out of 12 for all)", "Yes", ["Yes", "No"]); add_setting_str("prize_2", "Prize for rolling 2 (1 out of 37)", ""); add_setting_str("prize_3", "Prize for rolling 3 (1 out of 19)", "Wrestling in glitter-oil bath"); add_setting_str("prize_4", "Prize for rolling 4 (1 out of 13)", "Cooking Sphagetti Part 2"); add_setting_str("prize_5", "Prize for rolling 5 (1 out of 10)", "Be mean to dar"); add_setting_str("prize_6", "Prize for rolling 6 (1 out of 8)", "Instant 10 hour cumshow"); add_setting_str("prize_7", "Prize for rolling 7 (1 out of 7)", "Open mouth closeup"); add_setting_str("prize_8", "Prize for rolling 8 (1 out of 8)", "I change my name to BB"); add_setting_str("prize_9", "Prize for rolling 9 (1 out of 10)", "Thumbnail pose until 5000 people in the room"); add_setting_str("prize_10", "Prize for rolling 10 (1 out of 13)", "Sexy dancing in a bear costume"); add_setting_str("prize_11", "Prize for rolling 11 (1 out of 19)", "Free chance to tip me another 100 tokens!"); add_setting_str("prize_12", "Prize for rolling 12 (1 out of 37)", "I'll look up a cool gif for you"); add_setting_str("prize_13", "Prize for rolling 13 (empty to disable)", "Grand prize! You win nothing."); add_setting_str("chance_13", "Percent chance to roll 13", "0.5%"); add_setting_int("block_13", "Number of rolls required before 13 is possible", 0); add_setting_int("display_13", "Display 13 as this number instead:", 13, 2, 13); add_setting_str("advertising_msg", "Advertising message (empty to disable)", "Tip 22 to make our trained sloth roll some dice! Type /dice to see the prizes!"); add_setting_int("advertising_interval", "Advertising message interval in lines of text", 30); var win_13 = 0; var roll_count = 0; var chance_13 = parse_number(setting("chance_13"), -1) / 100; if (chance_13 < 0) { chance_13 = 0; notice_broadcaster("Couldn't parse chance to roll 13, defaulting to 0%"); } function find_dice(amount) { var rolls = [[],[],[[1,1]],[[1,2],[2,1]],[[1,3],[2,2],[3,1]],[[1,4],[2,3],[3,2],[4,1]],[[1,5],[2,4],[3,3],[4,2],[5,1]],[[1,6],[2,5],[3,4],[4,3],[5,2],[6,1]],[[2,6],[3,5],[4,4],[5,3],[6,2]],[[3,6],[4,5],[5,4],[6,3]],[[4,6],[5,5],[6,4]],[[5,6],[6,5]],[[6,6]]]; return rolls[amount][random_int(0, rolls[amount].length - 1)]; } function roll_dice() { roll_count++; if (roll_count > setting("block_13") && Math.random() < chance_13) { win_13++; if (setting("display_13") != 13) { var d = find_dice(setting("display_13")); return {"amt" : 13, "str" : ":pinkdie" + d[0] + " " + ":pinkdie" + d[1] + " "}; } else { return {"amt" : 13, "str" : ":pinkdie3 :pinkdie7 :pinkdie3 "}; } } var amt = 0; var str = ""; if (setting("equalize_chances") == "No") { var d = [random_int(1, 6), random_int(1, 6)]; amt = d[0] + d[1]; if (amt == setting("display_13")) { amt = random_int_except(2, 12, setting("display_13")); d = find_dice(amt); } str = ":pinkdie" + d[0] + " " + ":pinkdie" + d[1] + " "; } else { amt = random_int_except(2, 12, setting("display_13")); var d = find_dice(amt); str = ":pinkdie" + d[0] + " " + ":pinkdie" + d[1] + " "; } return {"amt" : amt, "str" : str}; } listen_tip(function(tip) { if (tip.amount != setting("roll_price")) return; if (is_game_over()) return; var roll = roll_dice(2); var prize = setting("prize_" + roll.amt); if (roll.amt == 13) roll.amt = setting("display_13"); if (prize == "") { notice(roll.str + tip.from_user + " rolled " + roll.amt + " " + setting("prize_lose")); } else { notice(roll.str + tip.from_user + " rolled " + roll.amt + " and won " + prize); } if (setting("remove_prizes") == "Yes") { set_setting("prize_" + roll.amt, ""); if (is_game_over()) notice(setting("game_won_msg")); } }); function prizes_left() { var count = 0; for (var i = 2; i < 14; i++) if (setting("prize_" + i) != "") count++; return count; } function is_game_over() { return prizes_left() == 0; } function notice_prizes_left(user) { if (is_game_over()) { notice(setting("game_won_msg")); return; } var s = "Prizes " + (setting("remove_prizes") == "Yes" ? "left " : "") + "for the dice game:\n"; for (var i = 2; i < 14; i++) { if (setting("prize_" + i) == "") continue; s += "Roll " + i + " for " + setting("prize_" + i) + "\n"; } s += setting("advertising_msg"); notice(s, user); } add_command("dice", 0, false, user_types.staff, function(msg) { notice_prizes_left(); }); add_command("dice", 0, false, user_types.guest, function(msg) { notice_prizes_left(msg.user); }); add_command("dice_stat", 0, false, user_types.broadcaster, function(msg) { notice_broadcaster("A total of " + roll_count + " rolls have been made for " + (roll_count * setting("roll_price")) + " tokens \n total wins: " + win_13 + "\n parsed win chance: " + chance_13); }); if (setting("advertising_msg").length > 0 && setting("advertising_interval") > 0) { interval_callback(function() { notice(setting("advertising_msg")); }, setting("advertising_interval")); } set_notice_color(setting("bot_color")); notice("Roll the Pink Dice has started!\n" + setting("advertising_msg"));
© Copyright Chaturbate 2011- 2024. All Rights Reserved.