Apps Home
|
My Uploads
|
Create an App
Gold Mine!
Author:
octoblue
Description
Source Code
Launch App
Current Users
Created by:
Octoblue
App Images
var version = '0.7'; var backgroundImage = '773a0718-5a37-4639-8dcc-14d7ac0d3cd4'; var re_reward = /\/reward ([1-9][0-9]*)/; var gold_diggers = {}; var token_spenders = {}; var tip_options = []; var item_list = []; var item_list_text; var user_started_digging = ''; var last_user = null; var last_goal = null; var announcement = 'The Gold Mine App ' + version + ' is currently active. Type /mine to dig for gold and /list for a list of things you can pay for with the gold or tokens. You have a 20 percent chance to find gold'; cb.settings_choices = [ {name: 'change_room_subject', type: 'choice', choice1: 'Yes', choice2: 'No', default: 'Yes', label: 'Change the room subject to announce game?'}, {name: 'announce_interval', type: 'int', minValue: 0, maxValue: 30, default: 10, label: 'The interval of posting a game announcement in the chat (set to 0 to disable).'}, {name: 'gold_vein', type: 'int', minValue: 0, default: 10, label: 'Pieces of gold should one gets if one hits a gold vein (set to 0 or 1 to disable gold veins completely).'}, {name: 'item_0_description', type: 'str', minLength: 1, maxLength: 255, label: "ITEM 1: Describe an item on the list (e.g., show butt).", defaultValue: 'show butt'}, {name: 'item_0_gold', type: 'int', minValue: 1, default: 100, label: "ITEM 1: How many gold pieces have to be traded in for the item?"}, {name: 'item_0_tokens', type: 'int', minValue: 1, default: 100, label: 'ITEM 1: How many tokens are necessary to redeem with tokens only?'}, {name: 'item_1_description', type: 'str', minLength: 1, maxLength: 255, label: "ITEM 2: Describe another item. Leave blank for no more items on list.", required: false}, {name: 'item_1_gold', type: 'int', minValue: 0, default: 100, label: "ITEM 2: How many gold pieces have to be traded in for the item (set to 0 to disable purchase by gold pieces)?"}, {name: 'item_1_tokens', type: 'int', minValue: 1, default: 100, label: 'ITEM 2: How many tokens are necessary to redeem with tokens only?'}, {name: 'item_2_description', type: 'str', minLength: 1, maxLength: 255, label: "ITEM 3: Describe another item. Leave blank for no more items on list.", required: false}, {name: 'item_2_gold', type: 'int', minValue: 0, default: 100, label: "ITEM 3: How many gold pieces have to be traded in for the item (set to 0 to disable purchase by gold pieces)?"}, {name: 'item_2_tokens', type: 'int', minValue: 1, default: 100, label: 'ITEM 3: How many tokens are necessary to redeem with tokens only?'}, {name: 'item_3_description', type: 'str', minLength: 1, maxLength: 255, label: "ITEM 4: Describe another item. Leave blank for no more items on list.", required: false}, {name: 'item_3_gold', type: 'int', minValue: 0, default: 100, label: "ITEM 4: How many gold pieces have to be traded in for the item (set to 0 to disable purchase by gold pieces)?"}, {name: 'item_3_tokens', type: 'int', minValue: 1, default: 100, label: 'ITEM 4: How many tokens are necessary to redeem with tokens only?'}, {name: 'item_4_description', type: 'str', minLength: 1, maxLength: 255, label: "ITEM 5: Describe another item. Leave blank for no more items on list.", required: false}, {name: 'item_4_gold', type: 'int', minValue: 0, default: 100, label: "ITEM 5: How many gold pieces have to be traded in for the item (set to 0 to disable purchase by gold pieces)?"}, {name: 'item_4_tokens', type: 'int', minValue: 1, default: 100, label: 'ITEM 5: How many tokens are necessary to redeem with tokens only?'}, {name: 'item_5_description', type: 'str', minLength: 1, maxLength: 255, label: "ITEM 6: Describe another item. Leave blank for no more items on list.", required: false}, {name: 'item_5_gold', type: 'int', minValue: 0, default: 100, label: "ITEM 6: How many gold pieces have to be traded in for the item (set to 0 to disable purchase by gold pieces)?"}, {name: 'item_5_tokens', type: 'int', minValue: 1, default: 100, label: 'ITEM 6: How many tokens are necessary to redeem with tokens only?'}, {name: 'item_6_description', type: 'str', minLength: 1, maxLength: 255, label: "ITEM 7: Describe another item. Leave blank for no more items on list.", required: false}, {name: 'item_6_gold', type: 'int', minValue: 0, default: 100, label: "ITEM 7: How many gold pieces have to be traded in for the item (set to 0 to disable purchase by gold pieces)?"}, {name: 'item_6_tokens', type: 'int', minValue: 1, default: 100, label: 'ITEM 7: How many tokens are necessary to redeem with tokens only?'}, {name: 'item_7_description', type: 'str', minLength: 1, maxLength: 255, label: "ITEM 8: Describe another item. Leave blank for no more items on list.", required: false}, {name: 'item_7_gold', type: 'int', minValue: 0, default: 100, label: "ITEM 8: How many gold pieces have to be traded in for the item (set to 0 to disable purchase by gold pieces)?"}, {name: 'item_7_tokens', type: 'int', minValue: 1, default: 100, label: 'ITEM 8: How many tokens are necessary to redeem with tokens only?'}, {name: 'item_8_description', type: 'str', minLength: 1, maxLength: 255, label: "ITEM 9: Describe another item. Leave blank for no more items on list.", required: false}, {name: 'item_8_gold', type: 'int', minValue: 0, default: 100, label: "ITEM 9: How many gold pieces have to be traded in for the item (set to 0 to disable purchase by gold pieces)?"}, {name: 'item_8_tokens', type: 'int', minValue: 1, default: 100, label: 'ITEM 9: How many tokens are necessary to redeem with tokens only?'}, {name: 'item_9_description', type: 'str', minLength: 1, maxLength: 255, label: "ITEM 10: Describe another item. Leave blank for no more items on list.", required: false}, {name: 'item_9_gold', type: 'int', minValue: 0, default: 100, label: "ITEM 10: How many gold pieces have to be traded in for the item (set to 0 to disable purchase by gold pieces)?"}, {name: 'item_9_tokens', type: 'int', minValue: 1, default: 100, label: 'ITEM 10: How many tokens are necessary to redeem with tokens only?'} ]; cb.onDrawPanel( function(user) { var text; var gold = 0; if( user['user'] == cb.room_slug ) { if( last_goal == null ) { text = 'Welcome to the gold mine!'; } else { text = last_user + ' paid for ' + item_list[last_goal].item; } var digging_text; if( user_started_digging != '' ) { digging_text = user_started_digging + ' has found gold!'; } else { digging_text = 'Nobody has found gold yet!'; } return { 'template': 'image_template', 'layers': [ {'type': 'image', 'fileID': backgroundImage}, { 'type': 'text', 'text': text, 'top': 18, 'left': 75, 'fontSize': 11, 'color': '#C3962E' }, { 'type': 'text', 'text': digging_text, 'top': 38, 'left': 75, 'fontSize': 11, 'color': '#C3962E' } ] }; } else { if( gold_diggers[user['user']] != undefined ) gold = gold_diggers[user['user']]; if( gold == 1 ) { text = 'You have found ' + gold + ' piece of gold'; } else { text = 'You have found ' + gold + ' pieces of gold'; } return { 'template': 'image_template', 'layers': [ {'type': 'image', 'fileID': backgroundImage}, { 'type': 'text', 'text': text, 'top': 18, 'left': 75, 'fontSize': 11, 'color': '#C3962E' }, { 'type': 'text', 'text': 'Type /mine to find more gold', 'top': 38, 'left': 75, 'fontSize': 11, 'color': '#C3962E' } ] }; } }); cb.tipOptions( function(user) { return {options: tip_options, label: 'Select a choice:'}; }); cb.onTip( function(tip) { if( token_spenders[tip['from_user']] === undefined ) { token_spenders[tip['from_user']] = 0; } token_spenders[tip['from_user']] += tip['amount']; if( tip['message'].indexOf('Select a choice:') != 0 ) { var option = -1; for( var i = 0; i < item_list.length; i++ ) { if( tip['message'].indexOf(item_list[i].tokenDescription) === 0 ) { option = i; break; } } if( option != -1 ) { if( item_list[option] != undefined ) { if( token_spenders[tip['from_user']] < item_list[option].gold ) { cb.sendNotice('Error: You did not pay enough tokens to pay for this reward.', tip['from_user'], '#FFFFFF', '#FF0000', 'bolder'); } else { token_spenders[tip['from_user']] -= item_list[option].gold; cb.sendNotice(tip['from_user'] + ' traded in ' + item_list[option].gold + ' tokens for \'' + item_list[option].description + '\'', '', '#FFFFFF', '#C3962E', 'bolder'); last_user = tip['from_user']; last_goal = option; cb.drawPanel(); } } } } }); cb.onMessage( function(msg) { if (msg['m'].indexOf("/") === 0) { msg['m'] = msg['m'].toLowerCase(); msg['X-Spam'] = true; if( msg['m'] == "/mine" ) { var res = Math.floor((Math.random() * 5) + 1); if (res == 5) { res = Math.floor((Math.random() * 10) + 1); if( cb.settings.gold_vein > 1 ) { if (res == 10) { gold_found(msg['user'], true); } else { gold_found(msg['user'], false); } } else { gold_found(msg['user'], false); } } else { cb.sendNotice('You just found some dirt. Try again!', msg['user'], '#FFFFFF', '#8B4513', 'bolder'); } } else if( msg['m'] == '/list' ) { cb.sendNotice(item_list_text, msg['user'], '#FFFFFF', '#C3962E', 'bolder'); } else if( msg['m'].indexOf('/reward') === 0) { var re_reward_result = re_reward.exec(msg['m']); if (re_reward_result != null) { var reward = parseInt(re_reward_result[1]) - 1; if( reward < 0 ) { cb.sendNotice('Error: Command /reward failed. The reward you chose does not exist.', msg['user'], '#FFFFFF', '#FF0000', 'bolder'); } else { if( item_list[reward] === undefined ) { cb.sendNotice('Error: Command /reward failed. The reward you chose does not exist.', msg['user'], '#FFFFFF', '#FF0000', 'bolder'); } else { if( gold_diggers[msg['user']] === undefined ) { if( item_list[reward].tokensOnly ) { cb.sendNotice('Error: You can pay for this reward with tokens only.', msg['user'], '#FFFFFF', '#FF0000', 'bolder'); } else { cb.sendNotice('Error: You do not have enough gold to pay for this reward.', msg['user'], '#FFFFFF', '#FF0000', 'bolder'); } } else { if( gold_diggers[msg['user']] < item_list[reward].gold ) { if( item_list[reward].tokensOnly ) { cb.sendNotice('Error: You can pay for this reward with tokens only.', msg['user'], '#FFFFFF', '#FF0000', 'bolder'); } else { cb.sendNotice('Error: You do not have enough gold to pay for this reward.', msg['user'], '#FFFFFF', '#FF0000', 'bolder'); } } else { if( item_list[reward].tokensOnly ) { cb.sendNotice('Error: You can pay for this reward with tokens only.', msg['user'], '#FFFFFF', '#FF0000', 'bolder'); } else { gold_diggers[msg['user']] -= item_list[reward].gold; cb.sendNotice(msg['user'] + ' traded in ' + item_list[reward].gold + ' pieces of gold for \'' + item_list[reward].item + '\'', '', '#FFFFFF', '#C3962E', 'bolder'); last_user = msg['user']; last_goal = reward; cb.drawPanel(); } } } } } } else { cb.sendNotice('Error: Command /reward failed. Type something like "/reward 1" to trade in your gold for the first item on the list.', msg['user'], '#FFFFFF', '#FF0000', 'bolder'); } } } return msg; }); // displays a message to the user or the whole chat if a gold vein has been hit function gold_found(user, gold_vein) { if( gold_diggers[user] === undefined ) { gold_diggers[user] = 0; user_started_digging = user; } if( gold_vein ) { cb.sendNotice(user + ' hit a gold vein (' + cb.settings.gold_vein + ' pieces of gold)! Type /list for a list of rewards.', '', '#FFFFFF', '#C3962E', 'bolder'); gold_diggers[user] += cb.settings.gold_vein; } else { cb.sendNotice('You have found a piece of gold! Type /list for a list of rewards.', user, '#FFFFFF', '#C3962E', 'bolder'); gold_diggers[user] += 1; } cb.drawPanel(); } // announce the gold mine app to users joining the chat cb.onEnter( function(user) { cb.sendNotice(announcement, user['user'], '#FFFFFF', '#C3962E', 'bolder'); }); // update the announcement whether gold veins are enabled or not function update_announcement() { if( cb.settings.gold_vein > 1 ) { announcement += ' and a 2 percent chance to find a gold vein (' + cb.settings.gold_vein + ' pieces of gold)'; } announcement += '. Type /reward 1 to trade in your gold for the first item on the list of rewards.'; } // announce game in chat at predefined interval function announce_game() { cb.sendNotice(announcement, '', '#FFFFFF', '#C3962E', 'bolder'); cb.setTimeout(announce_game, cb.settings.announce_interval*60000); } // create item description for list function create_item(item, gold, tokens) { var tokens_only = gold > 0 ? false : true; var tip_description = item + ' [' + tokens + ' token'; if( tokens > 1 ) tip_description += 's'; tip_description += ']'; var item_description = item + ' ['; if( gold > 0 ) { item_description += gold + ' gold piece'; if( gold > 1 ) item_description += 's'; item_description += ' or '; } item_description += tokens + ' token'; if( tokens > 1 ) item_description += 's'; item_description += ']'; return {'item': item, 'itemDescription': item_description, 'tipDescription': tip_description, 'gold': gold, 'tokens': tokens, 'tokensOnly': tokens_only}; } // update the item list according to settings function update_item_list_and_tip_options() { item_list.push(create_item(cb.settings.item_0_description, cb.settings.item_0_gold, cb.settings.item_0_tokens)); if( cb.settings.item_1_description != '' ) { item_list.push(create_item(cb.settings.item_1_description, cb.settings.item_1_gold, cb.settings.item_1_tokens)); } if( cb.settings.item_2_description != '' ) { item_list.push(create_item(cb.settings.item_2_description, cb.settings.item_2_gold, cb.settings.item_2_tokens)); } if( cb.settings.item_3_description != '' ) { item_list.push(create_item(cb.settings.item_3_description, cb.settings.item_3_gold, cb.settings.item_3_tokens)); } if( cb.settings.item_4_description != '' ) { item_list.push(create_item(cb.settings.item_4_description, cb.settings.item_4_gold, cb.settings.item_4_tokens)); } if( cb.settings.item_5_description != '' ) { item_list.push(create_item(cb.settings.item_5_description, cb.settings.item_5_gold, cb.settings.item_5_tokens)); } if( cb.settings.item_6_description != '' ) { item_list.push(create_item(cb.settings.item_6_description, cb.settings.item_6_gold, cb.settings.item_6_tokens)); } if( cb.settings.item_7_description != '' ) { item_list.push(create_item(cb.settings.item_7_description, cb.settings.item_7_gold, cb.settings.item_7_tokens)); } if( cb.settings.item_8_description != '' ) { item_list.push(create_item(cb.settings.item_8_description, cb.settings.item_8_gold, cb.settings.item_8_tokens)); } if( cb.settings.item_9_description != '' ) { item_list.push(create_item(cb.settings.item_9_description, cb.settings.item_9_gold, cb.settings.item_9_tokens)); } item_list_text = 'You can trade in your gold pieces for the following things:'; for( var i = 0; i < item_list.length; i++ ) { item_list_text += '\n' + (i+1) + '. ' + item_list[i].itemDescription tip_options.push({label: item_list[i].tipDescription}); } item_list_text += '\n Type /reward 1 to trade in your gold for the first item on the list.' } // update the room subject function update_subject() { if (cb.settings.change_room_subject == 'Yes') { cb.changeRoomSubject( '[Gold Mine!] Earn free gold pieces by typing /mine. Pay for goals with your gold or tokens.'); } } function init() { update_announcement(); update_item_list_and_tip_options(); update_subject(); cb.sendNotice(announcement, '', '#FFFFFF', '#C3962E', 'bolder'); if( cb.settings.announce_interval > 0 ) { cb.setTimeout(announce_game, cb.settings.announce_interval*60000); } cb.drawPanel(); } init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.