A working version of everyone's favorite 50/50 game. had to code it myself because i couldnt seem to find a free mod for it for some reason. gimme feedback if there is a problem
SQLs
CREATE TABLE IF NOT EXISTS `fifty` (
`bet_id` int(11) NOT NULL AUTO_INCREMENT,
`bettor` int(4) NOT NULL,
`wager` int(4) NOT NULL,
`bet_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`bet_id`)
)
fifty.php
<?php
require_once('./Global/globals.php');
global $h,$ir;
//original mod by mark mascola August 11, 2011
if(isset($_POST['match']) && is_numeric($_POST['match'])){
$q=$db->query("SELECT * FROM fifty WHERE bet_id = {$_POST['match']}");
$r = $db->fetch_row($q);
$win = floor($r['wager']*(1.

);
if($ir['second'] < $r['wager']){
echo"<br />You are trying to bet more than you have";
$h->endpage();
exit;
}elseif($ir['userid'] == $r['bettor']){
echo"<br />You cannot match your own bets";
$h->endpage();
exit;
}else{
$db->query("UPDATE users SET second = second - {$r['wager']} WHERE userid={$ir['userid']}");
$j=rand(1,2);
if($j==1){//the winner is the original bettor
$db->query("UPDATE users SET second = second + ".$win." WHERE userid = {$r['bettor']}");
event_add($r['bettor'], "You won your 50/50 bet of ".$r['wager']." points and earned ".floor($r['wager']*(1.

)." points!");
event_add($ir['userid'], "You lost your 50/50 bet of ".$r['wager']." points.");
}
if($j==2){//the winner is the matcher
$db->query("UPDATE users SET second = second + ".$win." WHERE userid = {$ir['userid']}");
event_add($r['bettor'], "You lost your 50/50 bet of ".$r['wager']." points.");
event_add($ir['userid'], "You won your 50/50 bet of ".$r['wager']." points and earned ".floor($r['wager']*(1.

)." points");
}
//need to add events to both the bettor and the taker.. need to delete the bet and update players with points
$db->query("DELETE FROM fifty WHERE bet_id = {$r['bet_id']}");
}
}
if(isset($_POST['points']) && is_numeric($_POST['points'])){
if($_POST['points'] < 10){
echo "<br />You are not betting enough";
$h->endpage();
exit;
}
elseif($_POST['points'] > 5000){
echo "<br />You are trying to bet too much";
$h->endpage();
exit;
}
elseif($ir['second'] < $_POST['points']){
echo "<br />You are trying to bet more than you have";
$h->endpage();
exit;
}
else{
$db->query("UPDATE users SET `second` = `second` - {$_POST['points']} where userid={$userid}");
$db->query("INSERT INTO fifty VALUES('',{$ir['userid']},{$_POST['points']},unix_timestamp())");
}
}
echo"<h2>50/50 Points Game</h2>";
echo"<p>The rules are simple.<br /> 2 players wager the same bet, the winner gets 90% of the pot. The house keeps 10%</p>";
echo"<p>The maximum bet is 5000 points but you may wager more than once.</p>";
echo "<p>
<form method='post'>
<input type='text' name='points' size='8' maxlength='7'> points (10-5000)<br /><br />
<input type='submit' name='bet' value='Place Bet'>
</form>
</p>
<h3>Awaiting Bets</h3>
<p>
<table width='90%'>
<tr>
<th><b>Mobster</b></td>
<th><b>Points</b></td>
<th><b>Bet Age</b></td>
<th align='center'><b>Bet</b></td>
</tr>";
$q = $db->query("SELECT f.*,u.username FROM fifty f LEFT JOIN users u ON f.bettor = u.userid ORDER BY bet_id ASC");
while($r = $db->fetch_row($q)) {
echo"<tr>";
echo"<td>".$r['username']."</td>";
echo"<td>".$r['wager']."</td>";
echo"<td>".DateTime_Parse($r['bet_time'])."</td>";
echo "<td><form method='post'>";
echo"<input type='hidden' name='match' value='".$r['bet_id']."' /><input type='submit' value='Match Bet'></form></td>";
echo"</tr>";
}
echo"</table></p>";
?>