Samurai Legend Posted May 18, 2014 Share Posted May 18, 2014 I am creating a modification. This modification will be free. Screen Shot - [ATTACH=CONFIG]1470[/ATTACH] [ATTACH=CONFIG]1471[/ATTACH] I am now creating the cron file to choose the winners and credit them the money and update the latest winners. I will need advice on how to choose the winners using a cron... Quote Link to comment Share on other sites More sharing options...
Reecey12345 Posted May 19, 2014 Share Posted May 19, 2014 http://makewebgames.io/showthread.php/38737-Lottery-Mod?highlight=lottery take a look at the cron_lottery.php code! Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted May 20, 2014 Author Share Posted May 20, 2014 (edited) How should I make the system choose the winner? Person with the most tickets? Random...? I don't want to do them two above as it won't be fair... But I need an idea... Edited May 20, 2014 by Samurai Legend Quote Link to comment Share on other sites More sharing options...
wrux Posted May 20, 2014 Share Posted May 20, 2014 How should I make the system choose the winner? Person with the most tickets? Random...? I don't want to do them two above as it won't be fair... But I need an idea... Lotterys are always completely random. Random is the most fair way of doing it, everyone with 1 ticket has an equal chance Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted May 20, 2014 Author Share Posted May 20, 2014 But in my case...Anyone can buy up to 50 tickets... I got one but I am not sure of it... I will use the rand function 1 - 50. Which ever it selects users with that amount of tickets. Will then be randomly chosen. So for example. The rand chose 23. And theres about 3 people with 23 tickets. It will then randomly choose the person. Quote Link to comment Share on other sites More sharing options...
wrux Posted May 20, 2014 Share Posted May 20, 2014 But in my case...Anyone can buy up to 50 tickets... I got one but I am not sure of it... I will use the rand function 1 - 50. Which ever it selects users with that amount of tickets. Will then be randomly chosen. So for example. The rand chose 23. And theres about 3 people with 23 tickets. It will then randomly choose the person. Then players would have the exact same chance despite how many tickets they have? Without putting too much thought into it, this is how i'd do it.. I would just make a table with 1 field; userid. Each person can buy one ticket at a time and it adds another record to the lottery table. Once a week run the lottery event using Mysql Event Scheduler. Select someone at random, update their money, add an event and truncate the table (this could probably be done using a stored procedure too). Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted May 20, 2014 Share Posted May 20, 2014 $res = $db->query(SELECT * FROM `tablename` WHERE tickets > 0 ORDER BY RAND() DESC LIMIT 3); $i = 0; while($row = $db->fetch_row($res)) { $i++; if($i == 1) { #1st } else if($i == 2) { #2nd } else if($i == 3) { #3rd } } Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted May 20, 2014 Author Share Posted May 20, 2014 Haha, I was just going to do something like that. I took wrux advice! Thanks all. Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted May 20, 2014 Author Share Posted May 20, 2014 (edited) Something like this right? <?php require_once('../globals_nonauth.php'); /* if (!isset($argc)) { $argc = 0; } if ($argc == 2) { if ($argv[1] != $_CONFIG['code']) { exit; } } else if (!isset($_GET['code']) || $_GET['code'] !== $_CONFIG['code']) { exit; }*/ $query = $db->query("SELECT SUM(`raffle_tickets`) AS total_raffle_tickets FROM `users`"); $amount = $db->fetch_row(); $payment_one = money_formatter($set['payment-one_raffle'] * $amount['total_raffle_tickets']); $payment_two = money_formatter($set['payment-two_raffle'] * $amount['total_raffle_tickets']); $payment_three = money_formatter($set['payment-three_raffle'] * $amount['total_raffle_tickets']); $query = $db->query(SELECT `raffle_tickets`, `username`, `userid` FROM `users` WHERE raffle_tickets > 0 ORDER BY RAND() DESC LIMIT 3); $i = 0; while($row = $db->fetch_row($query)) { $i++; if($i == 1) { $db->query("UPDATE `users` SET `money` = `money` + $payment_one WHERE `userid` = {$row['userid']}"); $db->query("UPDATE `raffle_winners` SET `user` = {$row['userid']} `amount` = $payment_one WHERE `position` = '1st.'"); } else if($i == 2) { $db->query("UPDATE `users` SET `money` = `money` + $payment_two WHERE `userid` = {$row['userid']}"); $db->query("UPDATE `raffle_winners` SET `user` = {$row['userid']} `amount` = $payment_two WHERE `position` = '2nd.'"); } else if($i == 3) { $db->query("UPDATE `users` SET `money` = `money` + $payment_three WHERE `userid` = {$row['userid']}"); $db->query("UPDATE `raffle_winners` SET `user` = {$row['userid']} `amount` = $payment_three WHERE `position` = '3rd.'"); } ?> Edited May 20, 2014 by Samurai Legend Quote Link to comment Share on other sites More sharing options...
Dayo Posted May 20, 2014 Share Posted May 20, 2014 (edited) What you could do is make a new table wit the fields [ticketNo, User] then when a user buys a ticket it inserts a new row (or 50 if they buy 50) then when you decide a winner just select the min and max id and do a rand with these numbers (do it via php rather then sql as its more efficient when you are dealing with large quantities of data). Once the lottery is complete truncate the table and start again. Also from your screenshoot you will be injecting 125% more cash into the game each time as i presume you have dome it like prize 1 = 1000 * no. of tickets prize 2 = 750 * no. of tickets prize 3 = 500 * no. of tickets would be better to do prize 1 = 444 * no. of tickets prize 2 = 333 * no.of Tickets prize 2 = 222 * no.of tickets Edited May 20, 2014 by Dayo Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 20, 2014 Share Posted May 20, 2014 You can take a look at how I did my winners for my weekly lotto on NWE https://github.com/KyleMassacre/Weekly-Lotto/blob/master/daily_cron.php Quote Link to comment Share on other sites More sharing options...
Jason-x Posted May 20, 2014 Share Posted May 20, 2014 I'd do the sql for tickets like. Ticketid. Ticket owner. Then have the draw pick a random ticket id to select a winner. So like if the first person buys 23 tickets. They will had ticketid 1 to 23 and so on Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted May 20, 2014 Author Share Posted May 20, 2014 [MENTION=64684]Dayo[/MENTION] & Jason-x - I was thinking about that before. When someone buys a ticket it gets inserted in another table. More tickets you buy. The more chance you have of winning. Thank Dayo and Jason-x for the feedback and advice. [MENTION=68711]KyleMassacre[/MENTION] - Thanks Kyle! Life saver you are hehe! Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 20, 2014 Share Posted May 20, 2014 @KyleMassacre - Thanks Kyle! Life saver you are hehe! No prob. MrDJK helped me with that to fine tune it Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted May 20, 2014 Author Share Posted May 20, 2014 So far I have this... <?php require('globals.php'); if (!isset($_GET['action'])) { $_GET['action'] = ''; } switch ($_GET['action']) { case "buyticket": buy_ticket(); break; case "view": last_winners(); break; default: index(); break; } function index() { echo "<h3><u>Raffle</u></h3>"; global $db, $set, $userid, $ir, $goback; $amount = $db->num_rows($db->query("SELECT * FROM raffle_tickets")); $payment_one = money_formatter($set['payment-one_raffle'] * $amount); $payment_two = money_formatter($set['payment-two_raffle'] * $amount); $payment_three = money_formatter($set['payment-three_raffle'] * $amount); $usersticket = $db->num_rows($db->query("SELECT * FROM raffle_tickets WHERE userid=$userid")); echo "<hr width='75%'>One ticket costs ¥1,000.<br />You can buy up to 50 tickets..<br /> $amount raffle tickets have been bought so far. $usersticket have been bought from you.<br /><br /> Current Payouts -<br /> 1st. $payment_one <br /> 2nd. $payment_two <br /> 3rd. $payment_three <br /><hr width ='75%'> Tables reset daily and prizes are given out. Prize money will go up with each ticket.<br/> Three lucky winners will be taking away the prizes! <hr width ='75%'> > <a href = 'raffle.php?action=buyticket'>Buy a ticket for ¥1,000</a><br /> > <a href = 'raffle.php?action=view'>View latest winners</a><br/> $goback <hr width ='75%'>"; } function buy_ticket() { global $db, $set, $userid, $ir, $goback, $h; echo "<h3><u>Tickets</u></h3>"; $usersticket = $db->num_rows($db->query("SELECT * FROM raffle_tickets WHERE userid=$userid")); if ($usersticket > 49) { error("You can only buy up to 50 raffle tickets."); $h->endpage(); die(); } if ($ir['money'] >= 1000) { confirmation('You bought one ticket for ¥1,000.'); $db->query("UPDATE `users` SET `money` = `money` - 1000 WHERE `userid` = $userid"); $db->query("INSERT INTO `raffle_tickets` VALUES ('','$userid')"); } else { error('You need ¥1,000'); $h->endpage(); die(); } } function last_winners() { global $db, $set, $userid, $ir, $goback, $h; echo "<h3><u>Latest Winners</u></h3><hr width ='50%'>"; $query = $db->query("SELECT u.username, u.userid, r.position, r.amount FROM `users` u INNER JOIN `raffle_winners` r ON u.userid = r.user"); echo "<table width='75%' cellspacing='1' cellpadding='1' class='table'> <tr> <th>Position</th> <th>User</th> <th>Amount Won</th> </tr> "; while ($r = $db->fetch_row($query)) { $amount = money_formatter($r['amount']); echo "<tr><td>{$r['position']}</td> <td><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a></td> <td>$amount</td>"; } echo "</tr></table><hr width ='75%'>$goback<hr width ='75%'>"; } $h->endpage(); ?> Now I am moving onto the cron xD Quote Link to comment Share on other sites More sharing options...
dnenb Posted May 20, 2014 Share Posted May 20, 2014 Cool idea! I'm going to use it when you finish it :) Quote Link to comment Share on other sites More sharing options...
Reecey12345 Posted May 20, 2014 Share Posted May 20, 2014 Nice, can't wait for when you finish this I will be using it :-) So far nice job too Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted May 20, 2014 Author Share Posted May 20, 2014 [MENTION=69116]dnenb[/MENTION] - Thanks man! :) [MENTION=70260]Reecey12345[/MENTION] - Thanks too! :) Quote Link to comment Share on other sites More sharing options...
dnenb Posted July 6, 2014 Share Posted July 6, 2014 Hey, did you finish this? :) Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted July 7, 2014 Author Share Posted July 7, 2014 Hey, did you finish this? :) http://makewebgames.io/showthread.php/44788-Raffle-Modification?highlight=Raffle I finished it :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.