Jump to content
MakeWebGames

Raffle


Recommended Posts

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...

249052462_ScreenShot2014-05-19at00_42_05.png.5a15795e8c5aac1f673076c083c4aa5b.png

2056865379_ScreenShot2014-05-19at00_42_39.png.0d40d1eda04b43ccb75fcccd98ad0bd0.png

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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 by Samurai Legend
Link to comment
Share on other sites

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 by Dayo
Link to comment
Share on other sites

[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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...