Jump to content
MakeWebGames

Recommended Posts

Posted

Hey there,

This is a mod of a Lottery mod posted awhile back, and it worked perfectly in my game with no bugs. Many of the free ones on here, I had the same issue: they either didn't credit users, or had some type of bug or another. Winner is selected weekly, and the cost per ticket and max tickets allowed can changed at the top ($cost and $tick).

lottery.php:

<?php

include "globals.php";

switch($_GET['action'])
{
  case 'buysub': buy_sub(); break;
  default: index(); break;
}


function index()
{
  global $db,$ir,$userid;

  $cost = 50;
  $tick = 5;

  $sql = sprintf("SELECT * FROM `lottery`");
  $query = $db->query($sql);
  $row = $db->fetch_row($query);

  echo sprintf(" <center>[img=lottery.jpg]</center>


<font color = 'black' size = '3' /><b />
              You currently have %d tickets
              and are able to purchase up to %d tickets per week.
              Each ticket costs $%d. The jackpot is $%u.", $ir['lottery'], $tick,
              $cost, $row['jackpot']);

  echo " 

        <form action = 'lottery.php?action=buysub' method = 'post' />
        <input type = 'text' name = 'buysub' value = '1' /> 


        <input type = 'submit' value = 'Buy Tickets' /> </form>";
}


function buy_sub()
{
  global $db,$ir,$userid;

  $_POST['buysub'] = abs((int) $_POST['buysub']);
  $cost = 50;
  $price = $cost * $_POST['buysub'];

  if($_POST['buysub'] > 5)
  {
     die("You can't buy more than 5 lottery tickets. <a href = 'index.php' />Go Home</a>");
  }

  if($ir['lottery'] >= 5)
  {
     die("You have already purchased 5 tickets this week. <a href = 'index.php' />Go Home</a>");
  }

  if($_POST['buysub'] + $ir['lottery'] > 5)
  {
     die("You can't buy this many tickets because you would exceed the maximum amount of allowed tickets. <a href = 'index.php' />Go Home</a>");
  }

  if($ir['money'] < $price)
  {
     die("You don't have enough money to buy {$_POST['buysub']} tickets. <a href = 'index.php' />Go Home</a>");
  }

  else
  {
     print "You have bought {$_POST['buysub']} lottery tickets. <a href = 'index.php' />Go Home</a>";

     $sql = sprintf("UPDATE `users` SET `lottery` = `lottery` + '%d',
                 `money` = `money` - '%d'
                 WHERE `userid` = ('%u')",
                 $_POST['buysub'], $price, $userid);

     $db->query($sql);


     $sql1 = sprintf("INSERT INTO `lottery` (id,userid, amount) VALUES (%d,%u, %d)",
                  '',$userid, $price);

     $db->query($sql1);


     $sql2 = sprintf("UPDATE `lottery` SET `jackpot` = `jackpot` + '%d'",
                  $price);

     $db->query($sql2);
  }
}


$h->endpage();
?>

 

Change text, etc as desired of course. I inserted a pic at the top of mine, you can change it just text if you like.

Insert this into your cron_weekly.php:

$sql = $db->query("SELECT * FROM `lottery`");
$rows = $db->num_rows($sql);
$row = $db->fetch_row($sql);
$winner = rand(1,$rows);
$winnerq = sprintf("SELECT `userid` FROM `lottery` WHERE `id` = %d",
$winner);
$winnerq1 = $db->query($winnerq);
$user = $db->fetch_row($winnerq1);

$credit = sprintf("UPDATE `users` SET `money` = `money` + %d WHERE `userid` = (%u)",
$row['jackpot'],
$user['userid']);
$db->query($credit); 
event_add($user['userid'],"You won the MegaCorp lottery and were credited \${$row['jackpot']}",$c); 

$db->query("UPDATE `users` SET `lottery` = 0");
$db->query("TRUNCATE TABLE `lottery`");

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