Advertisement
Guest User

Heads or tails (hort)

a guest
Sep 29th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. <?php
  2. class hort extends Plugin {
  3.  
  4.     function isTriggered() {
  5.  
  6.         if(!isset($this->info['text'])) {
  7.             $this->sendOutput($this->CONFIG['usage']);
  8.             return;
  9.         }
  10.  
  11.         $shuffle = array("heads","tails");
  12.         $result = array_rand($shuffle);
  13.         $bet = explode(" ", $this->info['text']);
  14.         if(!$this->userInDb()) $this->insertUser();
  15.         if (!$bet[1]){
  16.             $this->sendOutput("Please choose amount to bet");
  17.             return;
  18.         } else if ($bet[1] != "heads"){
  19.             $this->sendOutput("Please choose heads or tails");
  20.         } else if ($bet[1] != "tails"){
  21.             $this->sendOutput("Please choose heads or tails");
  22.         } else {
  23.             $this->sendOutput($this->info['nick'] . " You bet $" . (int)$bet[1] . " on " . $bet[0]);
  24.             if (!$this->check($bet[1])) {
  25.                 $this->sendOutput("You dont have enough funds to play");
  26.             } else {
  27.                 if($result == 0) {
  28.                     $result = "heads";
  29.                     if ($result == $bet[0]) {
  30.                         $this->sendOutput("You won");
  31.                         $this->win((int)$bet[1]);
  32.                     } else {
  33.                         $this->sendOutput("You lost");
  34.                         $this->lost((int)$bet[1]);
  35.                     }
  36.                 } else if ($result == 1) {
  37.                     $result = "tails";
  38.                     if ($result == $bet[0]) {
  39.                         $this->sendOutput("You won");
  40.                         $this->win((int)$bet[1]);
  41.                     } else {
  42.                         $this->sendOutput("You lost");
  43.                         $this->lost((int)$bet[1]);
  44.                     }
  45.                 }
  46.             }
  47.         }
  48.     }
  49.  
  50.     function userInDb() {
  51.         $res = $this->MySQL->sendQuery("SELECT 1 FROM hort WHERE nick='" . $this->info['nick'] . "'");
  52.         if($res['count'] == 0) return false;
  53.     return true;
  54.     }
  55.     function win($a) {
  56.         $res = $this->MySQL->sendQuery("UPDATE hort SET money = money + " . $a . " WHERE nick= '" . $this->info['nick'] . "'");
  57.     return true;
  58.     }
  59.     function lost($a) {
  60.         $res = $this->MySQL->sendQuery("UPDATE hort SET money = money - " . $a . " WHERE nick= '" . $this->info['nick'] . "'");
  61.     return true;
  62.     }
  63.     function check($a) {
  64.         $res = $this->MySQL->sendQuery("SELECT * FROM `hort` where nick = '" . $this->info['nick'] . "' and money >= " . $a . "");
  65.         if($res['count'] == 0) return false;
  66.     return true;
  67.     }
  68.     function insertUser() {
  69.         $this->MySQL->sendQuery("INSERT INTO hort (nick,money) VALUES ('" . $this->info['nick'] . "',100)");
  70.     return true;
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement