Apps Home
|
Create an App
Kiradivine's Lovense raffle
Author:
divine1
Description
Source Code
Launch App
Current Users
Created by:
Divine1
// Title: "KiraDivine's" Lovense control // Author: d_style // 30/10/2016 //command variables var COMMAND_INFO = '/info'; var COMMAND_HELP = '/helplove'; var COMMAND_SHOW_TICKETS = '/show'; var COMMAND_DRAW_WINNER = '/draw'; var COMMAND_REDRAW_WINNER = '/redraw'; var COMMAND_INSTANT_OFF = '/instoff'; var COMMAND_INSTANT_ON = '/inston'; // variables var tickets_sold = 0; var ticket_array = []; var l_ticket_array = []; var tipped_to_goal = 0; var goal_reached = false; var winner_is_drawn = false; var winning_ticket = -1; var winning_user = ""; var redraw = false; // Performers menu choices cb.settings_choices = [ {name: 'goal_description', label: 'Description.', type: 'str', minLength: 1, maxLength: 255, defaultValue: 'Every tip of 25 or more gives a chance to control my toy.'}, {name: 'control_time', label: 'Time in minutes the winner gets control over the toy.', type: 'int', minValue: 1, maxValue: 99, defaultValue: 10}, {name: 'goal_amount', label: 'Goal to be reached before the draw. (max 5000)', type: 'int', minValue: 1, maxValue: 5000, defaultValue: 1500}, {name: 'all_tips_count', label: 'Will all tips count towards the goal?', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No'}, {name: 'ticket_price', label: 'Minimum tip amount to get a free ticket.', type: 'int', minValue: 1, maxValue: 1000, defaultValue: 25}, {name: 'instant_option', label: 'Use the option to buy instant control?', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No'}, {name: 'instant_price', label: 'Price to buy instant control.', type: 'int', minValue: 0, maxValue: 5000, defaultValue: 1500}, {name: 'room_tags', label: 'Room tags.', type: 'str', minLength: 1, maxLength: 255, defaultValue: ' '} ]; cb.onEnter(function(user) { if (winner_is_drawn == true) { return; } else { cb.sendNotice(displayRules(),user['user'],'','#0018ff','bold','' ); } }); cb.onTip(function(tip) { if (winner_is_drawn == true || redraw == true) { return; } if(cb.settings.instant_option == 'Yes' && tip['amount'] == cb.settings.instant_price){ cb.sendNotice('User ' + tip['from_user'] + ' has bought instant control.','','','#0018ff','bold','' ); cb.sendNotice(tip['from_user'] + ' will now have control over my toy for ' + cb.settings.control_time + ' minutes.','','','#0018ff','bold','' ); cb.sendNotice('Tips of ' + cb.settings.ticket_price + ' or higher still gives you a free ticket.','','','#0018ff','bold','' ); return; } // Add the ticket to the array. if (tip['amount'] >= cb.settings.ticket_price){ addTicket(tickets_sold, tip['from_user']); tickets_sold += 1; tipped_to_goal += tip['amount']; }else if (cb.settings.all_tips_count == 'Yes'){ tipped_to_goal += tip['amount']; } if (tipped_to_goal >= cb.settings.goal_amount && !goal_reached){ goal_reached = true; cb.sendNotice('Goal is reached',cb.room_slug,'','#0018ff','bold','' ); } update_subject(); cb.drawPanel(); }); cb.onDrawPanel(function(user) { var fields = { template: '3_rows_of_labels', row1_label: 'Tips/Goal: ', row1_value: tipped_to_goal + '/' + cb.settings.goal_amount, row2_label: '', row2_value: '', row3_label: '', row3_value: '' }; if (user == null) { fields.row3_label = 'Tickets owned:'; fields.row3_value = '0'; return fields; } if (goal_reached == true) { fields.row1_label = 'Goal '; fields.row1_value = 'reached.'; } if (winner_is_drawn == true) { fields.row2_label = 'Winner is: '; fields.row2_value = winning_user; fields.row3_label = 'With ticket: '; fields.row3_value = winning_ticket; } // It's a registered user. fields.row3_label = 'Tickets owned:'; fields.row3_value = countUserTickets(user['user']); return fields; }); // user commands cb.onMessage(function (msg) { if (msg.user == cb.room_slug || msg.user == 'd_style') { msg['X-Spam'] = true; if (msg.m.indexOf(COMMAND_HELP) == 0) { cb.sendNotice(displayHelp(), msg['user'],'','#0018ff','bold','' ); } if (msg.m.indexOf(COMMAND_DRAW_WINNER) == 0) { drawWinner(); } if (msg.m.indexOf(COMMAND_REDRAW_WINNER) == 0) { if (winner_is_drawn == false){ cb.sendNotice('No redraw needed yet, first do the normal draw.', cb.room_slug,'','#0018ff','bold','' ); return; } winner_is_drawn = false; redraw = true; drawWinner(); } if (msg.m.indexOf(COMMAND_INFO) > -1) { cb.sendNotice(displayRules(),'','','#0018ff','bold','' ); } if (msg.m.indexOf(COMMAND_SHOW_TICKETS) > -1) { cb.sendNotice(showTickets(),'','','#0018ff','','' ); } if (msg.m.indexOf(COMMAND_INSTANT_OFF) > -1) { cb.settings.instant_option = 'No'; } if (msg.m.indexOf(COMMAND_INSTANT_ON) > -1) { cb.settings.instant_option = 'Yes'; } } return msg; }); // Returns a random integer between min and max // Using Math.round() will give you a non-uniform distribution! function getRandomInt (min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } // Display Help. function displayHelp() { return '\nThe following commands are available:\n' + COMMAND_HELP + ' -- show these command options.\n' + COMMAND_INFO + ' -- show raffle info to the users manually.\n' + COMMAND_SHOW_TICKETS + ' -- show a list with ticketholders.\n' + COMMAND_DRAW_WINNER + ' -- Draw a winner.\n' + COMMAND_REDRAW_WINNER + ' -- Do a redraw if necessary.\n' + COMMAND_INSTANT_OFF + ' -- Turn off the instant control option.\n' + COMMAND_INSTANT_ON + ' -- Turn on the instant control option.\n'; } function displayRules() { var msg = 'TAKE REMOTE CONTROL OVER MY TOY\n'; msg += '**** Wanna have a chance to control my toy?\n'; msg += '**** Every tip of ' + cb.settings.ticket_price + ' tokens or higher gives you a free ticket.\n'; msg += '**** Time you get control over my toy is ' + cb.settings.control_time + ' minutes.\n'; if (cb.settings.instant_option == 'Yes'){ msg += '\n**** Instant control can be bought for ' + cb.settings.instant_price + ' tokens.\n'; msg += '**** In case of instant control, tips of ' + cb.settings.ticket_price + ' tokens or higher still give you a free ticket.\n'; } msg += '\n**** A winner will only be drawn when the goal is reached'; msg += '\n**** A link to the control screen will be send to the winner in a PM'; msg += '\n**** Be in the room during the draw or there will be a redraw'; return msg; } // Show Rules. function showRules() { if (winner_is_drawn == true) { return; } cb.sendNotice(displayRules(),'','','#0018ff','bold','' ); cb.setTimeout(showRules, 300000); } // Count of the users tickets. function countUserTickets(username) { var ticket_count, i; if (ticket_array.length == 0) { return 0; } ticket_count = 0; for (i=0; i < ticket_array.length; ++i) { if (username == ticket_array[i].username) { ++ticket_count; } } return ticket_count; } // Add tickets to the ticket array. function addTicket(tip_index, username){ cb.sendNotice(username + " received ticket with number " + (tip_index+1) + "."); cb.sendNotice('Make sure you are in the room during the draw or there will be a redraw.',username,'','#0018ff','bold','' ); var ticket; ticket = {username: username, number: (tip_index+1) }; ticket_array[tip_index] = ticket; } function showTickets(){ var i; if (ticket_array.length == 0) { return; } var msg = '**** TICKET NUMBERS IN PLAY ****\n'; for (i=0; i < ticket_array.length; ++i) { msg += 'Ticket number ' + ticket_array[i].number + ' belongs to ' + ticket_array[i].username + '\n'; } return msg; } // Removes the tickets belong to a username. function removeTicketsByUser(tickets, username) { var i=0; while(i < tickets.length) { if (username == tickets[i].username) { tickets.splice(i, 1); } else { i += 1; } } } // Generate the Winners of the raffle. function getWinner() { var raffle_num, ticket; // Get a raffle ticket index. if (l_ticket_array.length == 1) { raffle_num = 0; }else{ raffle_num = getRandomInt (0, (l_ticket_array.length - 1)); } ticket = l_ticket_array[raffle_num]; winning_ticket = ticket.number; winning_user = ticket.username; removeTicketsByUser(l_ticket_array, ticket.username); return; } // Draw the Winners. function drawWinner() { if (redraw == false && winner_is_drawn == false){ l_ticket_array = ticket_array.slice(); } if (winner_is_drawn == true) { cb.sendNotice('Winner is already drawn.', cb.room_slug,'','#0018ff','bold','' ); return; }else if (l_ticket_array.length == 0){ cb.sendNotice('No tickets to draw from.', cb.room_slug,'','#0018ff','bold','' ); winner_is_drawn = true; return; } // Get the winner of the raffle. cb.sendNotice('Drawing the winner who will control my toy...', '','','#0018ff','bold','' ); getWinner(); cb.sendNotice(winning_user + ' with ticket number ' + winning_ticket + ' wins!!!', '','','#0018ff','bold','' ); cb.sendNotice(winning_user + ', are you ready to control my toy?', '','','#0018ff','bold','' ); winner_is_drawn = true; cb.drawPanel(); } // Update the room subject. function update_subject() { var new_subject = cb.settings.goal_description + ' ' + cb.settings.room_tags; cb.changeRoomSubject(new_subject); } // Initialize the application. function init() { update_subject(); showRules(); cb.sendNotice(displayHelp(), cb.room_slug,'','#0018ff','bold','' ); cb.sendNotice(displayHelp(), 'd_style','','#0018ff','bold','' ); cb.drawPanel(); } init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.