Guest User

HG by Merge and sekjun9878

a guest
Sep 11th, 2014
190
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*
  4. __PocketMine Plugin__
  5. name=HG Plugin
  6. description=HG SRVER PLUGIN
  7. version=1.0.0
  8. author=Merge and sekjun9878
  9. class=HungerGames
  10. apiversion=8,9
  11. */
  12.        
  13. class HungerGames implements Plugin{
  14.  
  15.  
  16. //Change These To Adjust Game Settings
  17.  
  18.     private $serverID = "[HG]";     //Server name
  19.     private $gamelength = 5;        //How long the game gos on for when it starts
  20.     private $gamewaittime = 1;      //How long to wait for players to join
  21.     private $minute = 6;            //This should be equal to $gamelength + $gamewaittime
  22.     private $minplayers = 4;        //The minimim amount of players to start the game (Max 16 Players A Game)
  23.     private $maxplayers = 16;       //The maximim amount of players to start the game (Max 16 Players A Game)
  24.    
  25.  
  26. //DO NOT Change These
  27.  
  28.  
  29.     private $api;
  30.    
  31.     private $playerspawncount = 0;
  32.    
  33.     private $gamestarted = false;
  34.    
  35.     private $server;
  36.     private $servname;
  37.    
  38.     private $spawn_loc = array(
  39.     array(170.5, 72, 170.5),
  40.     array(170.5, 72, 163.5),
  41.     array(175.5, 72, 157.5),
  42.     array(180.5, 72, 152.5),
  43.     array(188.5, 72, 152.5),
  44.     array(196.5, 72, 170.5),
  45.     array(201.5, 72, 157.5),
  46.     array(206.5, 72, 163.5),
  47.     array(206.5, 72, 170.5),
  48.     array(206.5, 72, 177.5),
  49.     array(201.5, 72, 183.5),
  50.     array(195.5, 72, 188.5),
  51.     array(188.5, 72, 188.5),
  52.     array(180.5, 72, 188.5),
  53.     array(175.5, 72, 183.5),
  54.     array(170.5, 72, 177.5)
  55.     );
  56.    
  57.    
  58.     public function __construct(ServerAPI $api, $server = false){
  59.         $this->api = $api;
  60.         $this->server = ServerAPI::request();
  61.     }
  62.    
  63.     public function init(){
  64.    
  65.         $this->api->console->register("hg", "Hunger Games v1.0.0", array($this, "commandHandler"));
  66.         $this->server->maxClients = $this->maxplayers;
  67.        
  68.         $this->api->addHandler("player.join", array($this, "eventHandler"), 100);
  69.         $this->api->addHandler("player.death", array($this, "eventHandler"), 100);
  70.         $this->api->addHandler("player.spawn", array($this, "eventHandler"), 100);
  71.         $this->api->addHandler("player.respawn", array($this, "eventHandler"), 100);
  72.         $this->api->addHandler("player.connect", array($this, "eventHandler"), 100);
  73.         $this->api->addHandler("player.block.touch", array($this, "eventHandler"), 100);
  74.         $this->api->addHandler("entity.health.change", array($this, "eventHandler"), 100);
  75.        
  76.         $this->api->level->loadLevel("HungerGames");
  77.        
  78.         $this->api->schedule(1200, array($this, "minuteSchedule"), array(), true);
  79.        
  80.         $this->api->level->get("HungerGames")->setSpawn(new Vector3(187, 80, 132));
  81.        
  82.         $this->servname = $this->server->name;
  83.         $this->server->name = "[OPEN] ECB Hunger Games   ".($this->serverID)."  ";
  84.     }
  85.    
  86.     private function getNextSpawn()
  87.     {
  88.         $this->playerspawncount = $this->playerspawncount + 1;
  89.         if($this->playerspawncount <= 16)
  90.             return $this->spawn_loc[$this->playerspawncount-1];
  91.         else
  92.         {
  93.             $this->playerspawncount = 1;
  94.             return $this->spawn_loc[$this->playerspawncount-1];
  95.         }
  96.     }
  97.     public function eventHandler($data, $event)
  98.     {
  99.         switch($event)
  100.         {
  101.             case "player.join":
  102.                 if($this->gamestarted == true)
  103.                 {
  104.                     $data->close();
  105.                 }
  106.                 break;
  107.             case "player.respawn":
  108.             case "player.death":
  109.                 if($this->gamestarted == true)
  110.                 {
  111.                     $data['player']->close();
  112.                 }
  113.                 if(count($this->api->player->getAll()) <= 1)
  114.                 {
  115.                     $this->api->chat->broadcast("Well Done You Are The Victor");
  116.                     $this->api->chat->broadcast("Game ended. Server reboot / cleanup...");
  117.                     $this->api->console->run("list");
  118.                     $this->server->name = "[Game Ended Restarting]  ".($this->serverID)."            ";
  119.                     sleep(7);
  120.                     $this->api->console->run("stop");
  121.                 }
  122.                 break;
  123.             case 'player.connect':
  124.                 if($this->gamestarted === true)
  125.                 {
  126.                     return false;
  127.                 }
  128.                 break;
  129.             case 'player.block.touch':
  130.                 if($this->gamestarted === false)
  131.                 {
  132.                     return false;
  133.                 }
  134.                 break;
  135.             case 'entity.health.change':
  136.                 if($this->gamestarted === false)
  137.                 {
  138.                     return false;
  139.                 }
  140.                 break;
  141.             case "player.spawn":
  142.                 if($this->gamestarted === true)
  143.                 {
  144.                     $data->close("The Game has already started!", false);
  145.                     break;
  146.                 }
  147.                
  148.                 $nextspawn = $this->getNextSpawn();
  149.                 $data->teleport(new Vector3($nextspawn[0], $nextspawn[1], $nextspawn[2]));
  150.                 $data->blocked = true;
  151.                 $data->sendChat("----------------------------------------------------");
  152.                 $data->sendChat("** Welcome to ECB Hunger Games 1");
  153.                 $data->sendChat("** Current Players: ".count($this->api->player->getAll())."/".$this->server->maxClients);
  154.                 $data->sendChat("** Have Fun and Good Luck!");
  155.                 $data->sendChat("** [NOTE] You are supposed to be stuck");
  156.                 $data->sendChat("** ".($this->minute-5)." minutes left until the game starts.");
  157.                 $data->sendChat("----------------------------------------------------");
  158.                 break;
  159.         }
  160.     }
  161.    
  162.     private function startGame()
  163.     {
  164.         $this->api->chat->broadcast("** The Game starts NOW");
  165.         $this->api->chat->broadcast("** The Game starts NOW");
  166.         $this->api->chat->broadcast("** The Game starts NOW");
  167.         $this->minute = $this->gamelength;
  168.         $this->gamestarted = true;
  169.         $this->server->name = "[IN PROGRESS] ECB Hunger Games ".($this->serverID)."  ";
  170.         exec("msg ".($this->serverID)." Started_".($this->serverID));
  171.         $this->playerspawncount = 0;
  172.         foreach($this->api->player->getAll() as $p)
  173.         {
  174.             $nextspawn = $this->getNextSpawn();
  175.             $p->teleport(new Vector3($nextspawn[0], $nextspawn[1], $nextspawn[2]));
  176.             $p->blocked = false;
  177.         }
  178.     }  
  179.  
  180.     public function minuteSchedule()
  181.     {
  182.         $this->minute--;
  183.         if($this->minute > $this->gamelength and $this->minute <= $this->gamelength + $this->gamewaittime)
  184.         {
  185.             $this->api->chat->broadcast("----------------------------------------------------");
  186.             $this->api->chat->broadcast("** Welcome to Hunger Games v1");
  187.             $this->api->chat->broadcast("** Current Players: ".count($this->api->player->getAll())."/".$this->server->maxClients);
  188.             $this->api->chat->broadcast("** Have Fun and Good Luck!");
  189.             $this->api->chat->broadcast("** [NOTE] You are supposed to be stuck before game start.");
  190.             $this->api->chat->broadcast("** ".($this->minute-5)." minutes left until the game starts.");
  191.             $this->api->chat->broadcast("----------------------------------------------------");
  192.         }
  193.         if($this->minute == $this->gamelength and count($this->api->player->getAll()) < $this->minplayers)
  194.             {
  195.                 $this->api->chat->broadcast("waiting for more players");
  196.                 $this->minute++;
  197.             }
  198.         if($this->minute == $this->gamelength)
  199.             {
  200.                 $this->startGame();
  201.             }
  202.         if($this->minute < $this->gamelength and $this->minute > 1)
  203.         {
  204.             $this->api->chat->broadcast(($this->minute)." minutes left");
  205.         }
  206.         if($this->minute == 1)
  207.         {
  208.             $this->api->chat->broadcast("1 minutes left. Spawning everyone to the spawn. Finish the game off!");
  209.             foreach($this->api->player->getAll() as $p)
  210.             {
  211.                 $this->playerspawncount = 0;
  212.                 $nextspawn = $this->getNextSpawn();
  213.                 $p->teleport(new Vector3($nextspawn[0], $nextspawn[1], $nextspawn[2]));
  214.             }
  215.         }
  216.         if($this->minute == 0)
  217.         {
  218.             $this->api->chat->broadcast("Game ended. Server reboot / cleanup...");
  219.             $this->api->console->run("list");
  220.             $this->server->name = "[Game Ended Restarting]  ".($this->serverID)."            ";
  221.             sleep(10);
  222.             $this->api->console->run("stop");
  223.         }
  224.     }
  225.    
  226.     public function commandHandler($cmd, $params, $issuer, $alias){
  227.         switch($cmd){
  228.         case "lobby":
  229.             if($gamestarted == true){
  230.             $issuer->sendChat("[lobby]: You cant TP in a Game!!");
  231.             break;
  232.             }
  233.             if(!($issuer instanceof Player)){
  234.             console("run command in game");
  235.             break;
  236.             }
  237.                 $level = $issuer->level->getName();
  238.                      switch($args[0]){
  239.                             case "":
  240.                               $spawn = $this->api->level->get($level)->getSpawn();
  241.                               $issuer->teleport($spawn);
  242.                               $issuer->sendChat("[lobby]: You teleported to lobby on ".$level);
  243.                             break;
  244.                             case "help":
  245.                                 $issuer->sendChat("------lobby Help------");
  246.                                 $issuer->sendChat("the spawn for this world is\n".$spawn);
  247.                                 $issuer->sendChat("/lobby - teleport to world lobby\n");
  248.                                 $issuer->sendChat("/lobby help - show this massage\n");
  249.                             break;
  250.                         }
  251.             break;}
  252.         $output = "";
  253.         if($cmd != "hg")
  254.         {
  255.             $output .= "Called via wrong command. Exiting..";
  256.             return $output;
  257.         }
  258.            
  259.         if($issuer instanceof Player)
  260.         {
  261.             $output .= "Command can only be run by console. Exiting...";
  262.             return $output;
  263.         }
  264.            
  265.         switch(array_shift($params)){
  266.             case "settimer":
  267.                 $this->minute = array_shift($params);
  268.                 $output .= "Success";
  269.                 break;
  270.             case "gettimer":
  271.                 $output .= $this->minute."\n";
  272.                 break;
  273.             case "start":
  274.                 if($this->gamestarted == true){
  275.                     $output = "Game Has Already Started\n";}
  276.                 console("Starting Game");
  277.                 sleep(1);
  278.                 $this->startGame();
  279.                 break;
  280.         }
  281.         return $output;
  282.     }
  283.    
  284.     public function __destruct()
  285.     {
  286.        
  287.     }
  288.  
  289. }
RAW Paste Data