Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have you purchased a mod and are struggling to install it? Cronwerks now installs mods for only $3/$2.50. Message Cronus to discuss the details or purchase.


This forum is now closed and has moved to a new location! Click here to find out why.

AuthorTopic: 50/50 game for redux  (Read 253 times)

windsor

  • Basic Member
  • *
  • Reputation Power: 7
  • windsor has no influence.
  • Offline Offline
  • Posts: 13
    • View Profile
50/50 game for redux
« on: August 11, 2011, 07:01:17 PM »
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.8));
   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.8))." 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.8))." 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>";   
   
?>
Logged
insanecriminal.com

windsor

  • Basic Member
  • *
  • Reputation Power: 7
  • windsor has no influence.
  • Offline Offline
  • Posts: 13
    • View Profile
Re: 50/50 game for redux
« Reply #1 on: August 11, 2011, 07:03:34 PM »
damned bbcode!!

wherever you see a smiley face should be the number eight followed by a closing bracket --- shift zero
Logged
insanecriminal.com

daftrude

  • Basic Member
  • *
  • Reputation Power: 3
  • daftrude has no influence.
  • Offline Offline
  • Posts: 5
    • View Profile
Re: 50/50 game for redux
« Reply #2 on: September 04, 2011, 09:42:19 PM »
whats the deal with the points? i have it working mostly but it wont go past betting, no matter what says im betting more than i have.
Logged
 


This forum is now closed and has moved to a new location! Click here to find out why.