-
Notifications
You must be signed in to change notification settings - Fork 0
/
lottery.php
71 lines (66 loc) · 2.66 KB
/
lottery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?
include("header.php");
if ($lockdb)
TheEnd("Lottery is currently not available!");
$tickcost = round($users[networth] / 10);
$jackpot = sqleval("SELECT cash FROM $lotterydb WHERE num=0 AND ticket=$tick_curjp;");
$lastjackpot = sqleval("SELECT cash FROM $lotterydb WHERE num=0 AND ticket=$tick_lastjp;");
$lastnum = sqleval("SELECT cash FROM $lotterydb WHERE num=0 AND ticket=$tick_lastnum;");
$lastwin = sqleval("SELECT cash FROM $lotterydb WHERE num=0 AND ticket=$tick_lastwin;");
$jackpotgrow = sqleval("SELECT cash FROM $lotterydb WHERE num=0 AND ticket=$tick_jpgrow;");
$tickets = mysql_query("SELECT * FROM $lotterydb WHERE num=$users[num];");
if ($do_ticket)
{
if (mysql_num_rows($tickets) >= $maxtickets)
TheEnd("You can't buy any more tickets!");
if ($users[cash] < $tickcost)
TheEnd("You don't have enough for a ticket!");
else
{
$tmp = sqleval("SELECT num FROM $playerdb ORDER BY num DESC LIMIT 1;");
$ticknum = mt_rand(1,3 * $tmp);
$jackpot += $tickcost;
mysql_query("INSERT INTO $lotterydb (num,ticket,cash) VALUES ($users[num],$ticknum,$tickcost);");
mysql_query("UPDATE $lotterydb SET cash=$jackpot WHERE num=0 AND ticket=$tick_curjp;");
$users[cash] -= $tickcost;
saveUserDataNet($users,"networth cash");
}
$tickets = mysql_query("SELECT * FROM $lotterydb WHERE num=$users[num];");
}
?>
Buying a lottery ticket is a good way to make extra money for our empire.<br>
When we buy a lottery ticket, that money goes into the jackpot, which goes up when nobody wins.<br>
Tickets cost $<?=commas($tickcost)?> and are valid for one drawing.<br>
Lottery drawings are held every day at noon.<br><br>
Current Jackpot: $<?=commas($jackpot)?><br><br>
<?=sqleval("SELECT COUNT(*) FROM $lotterydb WHERE num!=0;")?> tickets have been bought for the next drawing.<br>
The last lottery number was #<?=$lastnum?>,<br>
<?
if ($lastwin)
{
$enemy = loadUser($lastwin);
print "which $enemy[empire] (#$enemy[num]) had, winning a total of $".commas($lastjackpot)."!<br>\n";
}
else print "which nobody had, increasing the jackpot by another $".commas($jackpotgrow)."!<br>\n";
if (mysql_num_rows($tickets))
{
print "You have the following lottery tickets:";
while ($ticket = mysql_fetch_array($tickets))
print " #$ticket[ticket]";
}
else print "You currently have no lottery tickets";
print ".<br>\n";
if ($users[cash] < $tickcost)
print "You check your empire's treasury and find you don't have enough for a lottery ticket.<br>\n";
elseif (mysql_num_rows($tickets) < $maxtickets)
{
?>
<form method="post" action="<?=$config[main]?>?action=lottery">
<div>
<input type="submit" name="do_ticket" value="Buy a Lottery Ticket!">
</div>
</form>
<?
}
TheEnd("");
?>