Apps Home
|
Create an App
Sex Fun
Author:
salsoftip
Description
Source Code
Launch App
Current Users
Created by:
Salsoftip
// Title: Latest Token Raffle // Author: meatycock4u - Copyright Joshua Langley All rights reserved 2012. // Version: 1.4 (04/12/12) // Description: Raffle Ticket Application // Based on: Tip Goal - Copyright Chaturbate 2012. /*jslint continue: true, eqeq: true, plusplus: true, undef: true, sloppy: true, vars: true, white: true */ // vars var tickets_sold = 0; var ticket_array = []; var is_winners = false; var g_winners; // global because of delayed show winner. // vars timer var g_start_time = new Date().getTime(); var g_mins_left = 0; // Performers Choice Settings. cb.settings_choices = [ {name: 'tickets', label: 'Token Raffle Goal (Amount of Tickets)', type: 'int', minValue: 1, defaultValue: 200}, {name: 'goal_description', label: 'Description of Prizes', type: 'str', minLength: 1, maxLength: 255}, {name: 'draw_amount', label: 'Amount of Ticket Winners (1-10)', type: 'int', minValue: 1, defaultValue: 1, maxValue: 10}, {name: 'max_tickets', label: 'Maximum Tickets per User (0 = No Maximum Limit)', type: 'int', minValue: 0, defaultValue: 0}, {name: 'draw_minutes', label: 'Time Limit (Minutes, 0 = No Time Limit)', type: 'int', defaultValue: 0, minValue: 0, maxValue: 10080}, {name: 'user_win_many', label: 'Can One User win many times?', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No'} ]; // HANDLERS. // On a persons Tip. cb.onTip(function(tip) { if (is_winners == true) { return; } // Enforces a limit on how many tickets a person can get. max_tickets = cb.settings.max_tickets; if (max_tickets > 0) { user_tickets = countUserTickets( tip.from_user); if ((user_tickets + tip.amount) > max_tickets ) { tip.amount = max_tickets - user_tickets; if (tip.amount == 0) { return; } } } // Add the Tickets to the array. addTicket(tickets_sold, tip.from_user, tip.amount); tickets_sold += tip.amount; if (tickets_sold >= cb.settings.tickets) { tickets_sold = cb.settings.tickets; // If there is no timer then draw winners as per normal. drawWinners(); } update_subject(); cb.drawPanel(); }); // Re-Draw the Panel. cb.onDrawPanel(function(user) { var fields = { template: '3_rows_of_labels', row1_label: 'Tickets Sold / Left:', row1_value: tickets_sold + ' / ' + (cb.settings.tickets - tickets_sold), row2_label: 'Winners Drawn:', row2_value: cb.settings.draw_amount, row3_label: '', row3_value: '' }; if (user == null) { fields.row3_label = 'Owned / Max:'; fields.row3_value = '0 / ' + cb.settings.max_tickets; return fields; } if (is_winners == true) { fields.row2_value = 'Finished.'; } // Show the Performer how many minutes remain. if (user == cb.room_slug && cb.settings.draw_minutes > 0) { fields.row3_label = 'Time Left:'; fields.row3_value = getTimeLeft() + ' left'; return fields; } // It's a registered user. fields.row3_label = 'Owned / Max:'; fields.row3_value = countUserTickets(user) + ' / ' + cb.settings.max_tickets; return fields; }); // Draw the Winners. function drawWinners() { // Get the winners of the raffle. cb.chatNotice("Raffle Closed - Drawing the winning tickets..."); g_winners = getWinners(); // To delay the Winner Announcement and add suspense. cb.setTimeout(showWinners, 5000); is_winners = true; cb.drawPanel(); } // Timer functions. function updateTimer() { if (is_winners == true) { return; } var old_mins_left = g_mins_left; var elapsed_time = new Date().getTime() - g_start_time; cb.log('elapsed_time: ' + elapsed_time); var elapsed_mins = Math.floor(elapsed_time / 60000); cb.log('elapsed_mins: ' + elapsed_mins); if (elapsed_mins >= cb.settings.draw_minutes) { drawWinners(); } g_mins_left = cb.settings.draw_minutes - elapsed_mins; cb.log('old_mins_left: ' + old_mins_left + ', g_mins_left: ' + g_mins_left); if (old_mins_left == 0 || old_mins_left > g_mins_left) { if (old_mins_left == 0 || (g_mins_left >= 5 && (g_mins_left % 5) == 0) || (g_mins_left > 0 && g_mins_left < 5)) { cb.chatNotice(getTimeLeft() + ' left until the winners are drawn.'); cb.drawPanel(); } } // Grace period of up to 10 seconds. cb.setTimeout(updateTimer, 60000); } // Returns the time left in minutes as a string. function getTimeLeft() { if (g_mins_left == 0) { return 'No time'; } return g_mins_left + ((g_mins_left > 1) ? ' minutes' : ' minute'); } // HELPER FUNCTIONS // Update the room subject. function update_subject() { var new_subject = "Raffle Prizes: " + cb.settings.goal_description + " [" + tips_remaining() + " Tickets remaining]"; cb.log(new_subject); cb.changeRoomSubject(new_subject); } // The amount of tips remaining. function tips_remaining() { var r = cb.settings.tickets - tickets_sold; return (r < 0) ? 0 : r; } // Initialize the application. function init() { update_subject(); showRules(); if (cb.settings.draw_minutes > 0) { updateTimer(); } } init(); // RAFFLE FUNCTIONS // Show Rules. function showRules() { if (is_winners == true) { return; } var msg = 'Sex fun\n'; msg += 'I want to enter the penis inside your ass. Milk and landing on the lips.\n'; if (cb.settings.user_win_many == 'No') { msg += 'One Winner can have only one placing.\n'; } max_tickets = cb.settings.max_tickets; if (max_tickets > 0) { msg += 'Each User can only purchase a maximum of ' + max_tickets + ' tickets. Extra tickets tipped will be deducted as normal.'; } cb.chatNotice(msg); 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, amount) { // to clip tips that overflow the token amount. var overflow = (tip_index + amount) - cb.settings.tickets; if (overflow > 0) { amount -= overflow; } if (amount == 1) { cb.chatNotice(username + " received Ticket " + (tip_index+1) + "."); } else { cb.chatNotice(username + " received Tickets " + (tip_index+1) + "-" + (tip_index+amount) + "."); } var index, ticket, i; for (i=0; i < amount; ++i) { index = (tip_index + i); ticket = {username: username, number: (index+1) }; ticket_array[index] = ticket; } } // Generate the Winners of the raffle. function getWinners() { if (ticket_array.length == 0) { return []; } var l_winners = []; var draw_amount = cb.settings.draw_amount; var raffle_num, ticket, draw; if (cb.settings.user_win_many == 'No') { var l_ticket_array = ticket_array.slice(); for (draw=0; draw < draw_amount; ++draw) { // No tickets left so abort. if (l_ticket_array.length == 0) { break; } // 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]; l_winners.push(ticket); // Remove all the winners other tickets. removeTicketsByUser(l_ticket_array, ticket.username); } } else { // Get the raffle number indexes. var raffle_numbers = getUniqueNumbers(draw_amount, 0, (tickets_sold - 1)); for (draw=0; draw < draw_amount; ++draw) { raffle_num = raffle_numbers[draw]; ticket = ticket_array[raffle_num]; l_winners.push(ticket); } } return l_winners; } // 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; } } } /** * Gets a bunch of random unique numbers specified within the range. */ function getUniqueNumbers (count, min, max) { var arr = [], i; while(arr.length < count){ var randomnumber = getRandomInt(min, max); var found = false; for(i=0;i<arr.length;i++) { if(arr[i]==randomnumber) { found = true; break; } } if(!found) { arr[arr.length] = randomnumber; } } return arr; } /** * 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; } // end raffle functions. // Show the winners. function showWinners() { //cb.log(g_winners); if (g_winners.length == 0) { cb.chatNotice('There are no Winners for this raffle.'); return; } var winner, a; var msg = 'The Winners of the raffle are:'; for (a=0; a < g_winners.length; a++) { winner = g_winners[a]; msg += '\nplace ' + (a+1) + '. ' + winner.username + ' (Ticket ' + winner.number + ')'; } cb.chatNotice(msg); }
© Copyright Chaturbate 2011- 2026. All Rights Reserved.