Apps Home
|
Create an App
moloh_loto
Author:
molohlove
Description
Source Code
Launch App
Current Users
Created by:
Molohlove
cb.settings_choices = [ {label:'Ticket Price', name: 'ticket_price', type: 'int', minValue: 1, default: 7}, {label:'Starting Prize', name: 'start_val', type: 'int', minValue: 1, default: 1000}, {label:'Cat 4 - 3 winning Nr', name: 'cat4', type: 'int', minValue: 1, maxValue:50, default: 3}, {label:'Cat 3 - 4 winning Nr', name: 'cat3', type: 'int', minValue: 1, maxValue:50, default: 5}, {label:'Cat 2 - 5 winning Nr', name: 'cat2', type: 'int', minValue: 1, maxValue:70, default: 10}, {label:'Cat 1 - 6 winning Nr', name: 'cat1', type: 'int', minValue: 1, maxValue:100, default: 20}, {label:'Prize Notification', name: 'not1', type: 'int', minValue: 1, maxValue:100, default: 5} ]; var calculatePrizes = 0; var ticketsArr = new Object(); var winArr = new Object(); var winnersArr = new Object(); var winCatArr = new Object(); var winnersPerCatArr = new Object(); var totalPrizeVal = cb.settings['start_val']; var repeatTime = cb.settings['not1'] * 1000 * 60; var cat4P = cb.settings['cat4']; var cat3P = cb.settings['cat3']; var cat2P = cb.settings['cat2']; var cat1P = cb.settings['cat1']; var cat4Val, cat3Val, cat2Val, cat1Val; var cat4Prize, cat3Prize, cat2Prize, cat1Prize; cb.onTip(function (tip) { if(tip['amount'] == cb.settings['ticket_price']) buy_ticket(tip); }); cb.onMessage(function (msg) { if (msg['user'] == cb.room_slug && msg['m'].match(/\/drawprizes/i)) draw_rizes(); if(msg['m'].match(/\/tickets/i)) show_tickets(msg); if(msg['m'].match(/\/prizes/i)) show_prizes(msg); }); function buy_ticket(tip){ calculate_prizes(tip['amount']); if(typeof ticketsArr[tip['from_user']] === 'undefined' || !ticketsArr[tip['from_user']]) ticketsArr[tip['from_user']] = new Object(); var randArr = new Object(); while(Object.keys(randArr).length < 6){ var newNr = Math.floor((Math.random() * 49) + 1); if(inArray(newNr, randArr) == false) randArr[Object.keys(randArr).length] = newNr; } ticketsArr[tip['from_user']][Object.keys(ticketsArr[tip['from_user']]).length] = randArr; var ticketText = ''; for(i = 0; i < 6; i++) ticketText += randArr[i]+'_'; cb.sendNotice(' Congratulations, you bought a Loto 6/49 ticket. Your ticket numbers are: ' + ticketText+'. Buy more to win the grand prize', tip['from_user']); } function show_tickets(msg) { if(typeof ticketsArr[msg['user']] === 'undefined' || !ticketsArr[msg['user']]){ cb.sendNotice('You don\'t have any tickets...', msg['user']); } else { var nrTickets = Object.keys(ticketsArr[msg['user']]).length; cb.sendNotice('You have '+nrTickets+' tickets. Get more to increase your chances.', msg['user']); for(i = 0; i < nrTickets; i++){ var ticketText = ''; for(j = 0; j < 6; j++) ticketText += ticketsArr[msg['user']][i][j]+'_'; cb.sendNotice(ticketText, msg['user']); } } } function show_prizes(msg){ cb.sendNotice('Buy tickets for '+cb.settings['ticket_price']+' tokens a piece. More tickets increase your chances to win. Prize values go up with each tip.', msg['user']); cb.sendNotice('Prize list:', msg['user']); cb.sendNotice('Category 1 Pot: '+cat1Val+' tokens worth. To win you need 6 correct numbers', msg['user']); cb.sendNotice('Category 2 Pot: '+cat2Val+' tokens worth. To win you need 5 correct numbers', msg['user']); cb.sendNotice('Category 3 Pot: '+cat3Val+' tokens worth. To win you need 4 correct numbers', msg['user']); cb.sendNotice('Category 4 Pot: '+cat4Val+' tokens worth. To win you need 3 correct numbers', msg['user']); cb.sendNotice('type /tickets to see your tickets and numbers', msg['user']); } function calculate_prizes(tipVal) { if(typeof tipVal !== 'undefined' || tipVal) totalPrizeVal += tipVal; cat4Val = Math.round(cat4P * totalPrizeVal / 100); cat3Val = Math.round(cat3P * totalPrizeVal / 100); cat2Val = Math.round(cat2P * totalPrizeVal / 100); cat1Val = Math.round(cat1P * totalPrizeVal / 100); //cb.sendNotice('totalPrizeVal = '+totalPrizeVal+' cat1Val = '+cat1Val+' cat2Val = '+cat2Val+' cat3Val = '+cat3Val+' cat4Val = '+cat4Val); } function send_room_notification(){ if(calculatePrizes == 0) { cb.sendNotice('Buy tickets for '+cb.settings['ticket_price']+' tokens a piece. More tickets increase your chances to win. Prize values go up with each tip.'); cb.sendNotice('Prize list:'); cb.sendNotice('Category 1 Pot: '+cat1Val+' tokens worth. To win you need 6 correct numbers'); cb.sendNotice('Category 2 Pot: '+cat2Val+' tokens worth. To win you need 5 correct numbers'); cb.sendNotice('Category 3 Pot: '+cat3Val+' tokens worth. To win you need 4 correct numbers'); cb.sendNotice('Category 4 Pot: '+cat4Val+' tokens worth. To win you need 3 correct numbers'); cb.sendNotice('type /tickets to see your tickets and numbers'); cb.sendNotice('type /prizes to see the prize list'); cb.setTimeout(send_room_notification, repeatTime); } } function inArray(needle,haystack) { var count = Object.keys(haystack).length; for(var i=0; i < count; i++) if(haystack[i] === needle) return true; return false; } function draw_rizes() { if(Object.keys(ticketsArr).length >= 1){ if(Object.keys(winArr).length == 6){ var ticketText = ''; for(j = 0; j < 6; j++) ticketText += winArr[j]+'_'; cb.sendNotice('You already drew the winning numbers. You must restart the app to play again.'); cb.sendNotice('The winning numbers are: ' + ticketText); } else { while(Object.keys(winArr).length < 6){ var newNr = Math.floor((Math.random() * 49) + 1); if(inArray(newNr, winArr) == false) winArr[Object.keys(winArr).length] = newNr; } var ticketText = ''; for(j = 0; j < 6; j++) ticketText += winArr[j]+'_'; cb.sendNotice('The winning numbers are: ' + ticketText); } show_winners(winArr); } else { cb.sendNotice('There are no tickets, so there is no point to draw a winning number yet.', cb.room_slug); } } function show_winners(winArr) { var winNr; var k; winnersArr = new Object(); for(var userName in ticketsArr) { for(i = 0; i < Object.keys(ticketsArr[userName]).length; i++) { for(j = 0; j < 6; j++) { if(inArray(winArr[j], ticketsArr[userName][i]) == true){ if(typeof winnersArr[userName] === 'undefined' || !winnersArr[userName]) winnersArr[userName] = new Object(); if(typeof winnersArr[userName][i] === 'undefined' || !winnersArr[userName][i]) winnersArr[userName][i] = 0; winnersArr[userName][i]++; } } } } cb.sendNotice(' winArr = ' + JSON.stringify(winArr)); cb.sendNotice(' winnersArr = ' + JSON.stringify(winnersArr)); winCatArr[1] = 0; winCatArr[2] = 0; winCatArr[3] = 0; winCatArr[4] = 0; winCatArr[5] = 0; winCatArr[6] = 0; for(var userName in winnersArr) { for(key in winnersArr[userName]){ winCatArr[winnersArr[userName][key]]++; if(winnersArr[userName][key] == 3 || winnersArr[userName][key] == 4 || winnersArr[userName][key] == 5 || winnersArr[userName][key] == 6 ){ if(typeof winnersPerCatArr[userName] === 'undefined' || !winnersPerCatArr[userName]) winnersPerCatArr[userName] = new Object(); if(typeof winnersPerCatArr[userName][winnersArr[userName][key]] === 'undefined' || !winnersPerCatArr[userName][winnersArr[userName][key]]) winnersPerCatArr[userName][winnersArr[userName][key]] = 0; winnersPerCatArr[userName][winnersArr[userName][key]]++; } } } cb.sendNotice('winnersPerCatArr= '+JSON.stringify(winnersPerCatArr)); cb.sendNotice('winCatArr = ' + JSON.stringify(winCatArr)); if( winCatArr[3] != 0 ) cat4Prize = Math.round(cat4Val / winCatArr[3]); if( winCatArr[4] != 0 ) cat3Prize = Math.round(cat3Val / winCatArr[4]); if( winCatArr[5] != 0 ) cat2Prize = Math.round(cat2Val / winCatArr[5]); if( winCatArr[6] != 0 ) cat1Prize = Math.round(cat1Val / winCatArr[6]); var catPrizesArr = new Object(); catPrizesArr[3] = cat4Prize; catPrizesArr[4] = cat3Prize; catPrizesArr[5] = cat2Prize; catPrizesArr[6] = cat1Prize; for(userName in winnersPerCatArr) { for(cat in winnersPerCatArr[userName]) { var totalPrizeInTokens = winnersPerCatArr[userName][cat] * catPrizesArr[cat]; cb.sendNotice('Congratulations to '+userName+' for winning '+ winnersPerCatArr[userName][cat]+' category '+cat+' tickets worth '+totalPrizeInTokens+' tokens'); } } //cb.sendNotice('cat4Prize = ' + cat4Prize +' cat3Prize = ' + cat3Prize +' cat2Prize = ' + cat2Prize +' cat1Prize = ' + cat1Prize); } calculate_prizes(); cb.setTimeout(send_room_notification, repeatTime);
© Copyright Chaturbate 2011- 2025. All Rights Reserved.