Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- __PocketMine Plugin__
- name=HG Plugin
- description=HG SRVER PLUGIN
- version=1.0.0
- author=Merge and sekjun9878
- class=HungerGames
- apiversion=8,9
- */
- class HungerGames implements Plugin{
- //Change These To Adjust Game Settings
- private $serverID = "[HG]"; //Server name
- private $gamelength = 5; //How long the game gos on for when it starts
- private $gamewaittime = 1; //How long to wait for players to join
- private $minute = 6; //This should be equal to $gamelength + $gamewaittime
- private $minplayers = 4; //The minimim amount of players to start the game (Max 16 Players A Game)
- private $maxplayers = 16; //The maximim amount of players to start the game (Max 16 Players A Game)
- //DO NOT Change These
- private $api;
- private $playerspawncount = 0;
- private $gamestarted = false;
- private $server;
- private $servname;
- private $spawn_loc = array(
- array(170.5, 72, 170.5),
- array(170.5, 72, 163.5),
- array(175.5, 72, 157.5),
- array(180.5, 72, 152.5),
- array(188.5, 72, 152.5),
- array(196.5, 72, 170.5),
- array(201.5, 72, 157.5),
- array(206.5, 72, 163.5),
- array(206.5, 72, 170.5),
- array(206.5, 72, 177.5),
- array(201.5, 72, 183.5),
- array(195.5, 72, 188.5),
- array(188.5, 72, 188.5),
- array(180.5, 72, 188.5),
- array(175.5, 72, 183.5),
- array(170.5, 72, 177.5)
- );
- public function __construct(ServerAPI $api, $server = false){
- $this->api = $api;
- $this->server = ServerAPI::request();
- }
- public function init(){
- $this->api->console->register("hg", "Hunger Games v1.0.0", array($this, "commandHandler"));
- $this->server->maxClients = $this->maxplayers;
- $this->api->addHandler("player.join", array($this, "eventHandler"), 100);
- $this->api->addHandler("player.death", array($this, "eventHandler"), 100);
- $this->api->addHandler("player.spawn", array($this, "eventHandler"), 100);
- $this->api->addHandler("player.respawn", array($this, "eventHandler"), 100);
- $this->api->addHandler("player.connect", array($this, "eventHandler"), 100);
- $this->api->addHandler("player.block.touch", array($this, "eventHandler"), 100);
- $this->api->addHandler("entity.health.change", array($this, "eventHandler"), 100);
- $this->api->level->loadLevel("HungerGames");
- $this->api->schedule(1200, array($this, "minuteSchedule"), array(), true);
- $this->api->level->get("HungerGames")->setSpawn(new Vector3(187, 80, 132));
- $this->servname = $this->server->name;
- $this->server->name = "[OPEN] ECB Hunger Games ".($this->serverID)." ";
- }
- private function getNextSpawn()
- {
- $this->playerspawncount = $this->playerspawncount + 1;
- if($this->playerspawncount <= 16)
- return $this->spawn_loc[$this->playerspawncount-1];
- else
- {
- $this->playerspawncount = 1;
- return $this->spawn_loc[$this->playerspawncount-1];
- }
- }
- public function eventHandler($data, $event)
- {
- switch($event)
- {
- case "player.join":
- if($this->gamestarted == true)
- {
- $data->close();
- }
- break;
- case "player.respawn":
- case "player.death":
- if($this->gamestarted == true)
- {
- $data['player']->close();
- }
- if(count($this->api->player->getAll()) <= 1)
- {
- $this->api->chat->broadcast("Well Done You Are The Victor");
- $this->api->chat->broadcast("Game ended. Server reboot / cleanup...");
- $this->api->console->run("list");
- $this->server->name = "[Game Ended Restarting] ".($this->serverID)." ";
- sleep(7);
- $this->api->console->run("stop");
- }
- break;
- case 'player.connect':
- if($this->gamestarted === true)
- {
- return false;
- }
- break;
- case 'player.block.touch':
- if($this->gamestarted === false)
- {
- return false;
- }
- break;
- case 'entity.health.change':
- if($this->gamestarted === false)
- {
- return false;
- }
- break;
- case "player.spawn":
- if($this->gamestarted === true)
- {
- $data->close("The Game has already started!", false);
- break;
- }
- $nextspawn = $this->getNextSpawn();
- $data->teleport(new Vector3($nextspawn[0], $nextspawn[1], $nextspawn[2]));
- $data->blocked = true;
- $data->sendChat("----------------------------------------------------");
- $data->sendChat("** Welcome to ECB Hunger Games 1");
- $data->sendChat("** Current Players: ".count($this->api->player->getAll())."/".$this->server->maxClients);
- $data->sendChat("** Have Fun and Good Luck!");
- $data->sendChat("** [NOTE] You are supposed to be stuck");
- $data->sendChat("** ".($this->minute-5)." minutes left until the game starts.");
- $data->sendChat("----------------------------------------------------");
- break;
- }
- }
- private function startGame()
- {
- $this->api->chat->broadcast("** The Game starts NOW");
- $this->api->chat->broadcast("** The Game starts NOW");
- $this->api->chat->broadcast("** The Game starts NOW");
- $this->minute = $this->gamelength;
- $this->gamestarted = true;
- $this->server->name = "[IN PROGRESS] ECB Hunger Games ".($this->serverID)." ";
- exec("msg ".($this->serverID)." Started_".($this->serverID));
- $this->playerspawncount = 0;
- foreach($this->api->player->getAll() as $p)
- {
- $nextspawn = $this->getNextSpawn();
- $p->teleport(new Vector3($nextspawn[0], $nextspawn[1], $nextspawn[2]));
- $p->blocked = false;
- }
- }
- public function minuteSchedule()
- {
- $this->minute--;
- if($this->minute > $this->gamelength and $this->minute <= $this->gamelength + $this->gamewaittime)
- {
- $this->api->chat->broadcast("----------------------------------------------------");
- $this->api->chat->broadcast("** Welcome to Hunger Games v1");
- $this->api->chat->broadcast("** Current Players: ".count($this->api->player->getAll())."/".$this->server->maxClients);
- $this->api->chat->broadcast("** Have Fun and Good Luck!");
- $this->api->chat->broadcast("** [NOTE] You are supposed to be stuck before game start.");
- $this->api->chat->broadcast("** ".($this->minute-5)." minutes left until the game starts.");
- $this->api->chat->broadcast("----------------------------------------------------");
- }
- if($this->minute == $this->gamelength and count($this->api->player->getAll()) < $this->minplayers)
- {
- $this->api->chat->broadcast("waiting for more players");
- $this->minute++;
- }
- if($this->minute == $this->gamelength)
- {
- $this->startGame();
- }
- if($this->minute < $this->gamelength and $this->minute > 1)
- {
- $this->api->chat->broadcast(($this->minute)." minutes left");
- }
- if($this->minute == 1)
- {
- $this->api->chat->broadcast("1 minutes left. Spawning everyone to the spawn. Finish the game off!");
- foreach($this->api->player->getAll() as $p)
- {
- $this->playerspawncount = 0;
- $nextspawn = $this->getNextSpawn();
- $p->teleport(new Vector3($nextspawn[0], $nextspawn[1], $nextspawn[2]));
- }
- }
- if($this->minute == 0)
- {
- $this->api->chat->broadcast("Game ended. Server reboot / cleanup...");
- $this->api->console->run("list");
- $this->server->name = "[Game Ended Restarting] ".($this->serverID)." ";
- sleep(10);
- $this->api->console->run("stop");
- }
- }
- public function commandHandler($cmd, $params, $issuer, $alias){
- switch($cmd){
- case "lobby":
- if($gamestarted == true){
- $issuer->sendChat("[lobby]: You cant TP in a Game!!");
- break;
- }
- if(!($issuer instanceof Player)){
- console("run command in game");
- break;
- }
- $level = $issuer->level->getName();
- switch($args[0]){
- case "":
- $spawn = $this->api->level->get($level)->getSpawn();
- $issuer->teleport($spawn);
- $issuer->sendChat("[lobby]: You teleported to lobby on ".$level);
- break;
- case "help":
- $issuer->sendChat("------lobby Help------");
- $issuer->sendChat("the spawn for this world is\n".$spawn);
- $issuer->sendChat("/lobby - teleport to world lobby\n");
- $issuer->sendChat("/lobby help - show this massage\n");
- break;
- }
- break;}
- $output = "";
- if($cmd != "hg")
- {
- $output .= "Called via wrong command. Exiting..";
- return $output;
- }
- if($issuer instanceof Player)
- {
- $output .= "Command can only be run by console. Exiting...";
- return $output;
- }
- switch(array_shift($params)){
- case "settimer":
- $this->minute = array_shift($params);
- $output .= "Success";
- break;
- case "gettimer":
- $output .= $this->minute."\n";
- break;
- case "start":
- if($this->gamestarted == true){
- $output = "Game Has Already Started\n";}
- console("Starting Game");
- sleep(1);
- $this->startGame();
- break;
- }
- return $output;
- }
- public function __destruct()
- {
- }
- }
RAW Paste Data