This site works best with JavaScript enabled. Please enable JavaScript to get the best experience from this site.
<?php /* __PocketMine Plugin__ name=CTF description=minigame version=0.1.0 author=MR.ahmad class=CTF apiversion=10,11,12,13 */ /* Do not use this plugin's code without permission from author. * install clearinv plugin from pocketmine forums * install warp plugin as well */ class CTF implements Plugin{ private $api, $path; public function __construct(ServerAPI $api, $server = false){ $this->api = $api; } public function init(){ $this->api->console->register("base", "get assigned and Teleport to your team base.", array($this, "command")); $this->api->console->register("warpbase", "Warps a player back to their base", array($this, "command")); $this->api->console->register("setb ", "usage: [/setb r] to set blue return, [/setb f] to set flag, [/setb s] to set spawn", array($this, "command")); $this->api->console->register("setr ", "usage: [/setr r] to set red return, [/setr f] to set flag, [/setr s] to set spawn", array($this, "command")); $this->api->console->register("lobbyset", "usage: set the lobby spawn of your ctf world", array($this, "command")); $this->api->ban->cmdWhitelist("base"); $this->api->ban->cmdWhitelist("warpbase"); $this->api->schedule(120*20,array($this,"Points"),array(),true); $this->api->schedule(900*20, array($this, "EndGame"), array(), true); $this->api->addHandler("player.join", array($this, "handler")); //tps a player to the assigned lobby, if one is assigned $this->api->addHandler("player.spawn", array($this,"handler")); //if a player clicks respawn when they die, and are on a team, they are sent back to their base $this->api->addHandler("player.block.break", array($this, "handler")); //if player is on a team, he can only break the flag $this->api->addHandler("player.interact", array($this,"handler")); //if a player hits a player on his team, he is told not to, and no damage is taken $this->api->addHandler("player.block.place", array($this, "handler")); //if player is on a team, he can only place in the flag spot $this->api->addHandler("player.quit", array($this, "handler")); // if a player quits, or is kicked, he is taken out of his team if he is on one $this->config = new Config($this->api->plugin->configPath($this)."CTF.yml", CONFIG_YAML, array("PLEASE AVOID EDITING THIS UNLESS YOU KNOW WHAT YOU ARE DOING!!!", "Red-flag" => array(), "Blue-flag" => array(), "Blue-return" => array(), "Red-return" => array(), "Red-base" => array(), "Blue-base" => array(), "Name-of-ctfworld" => "world", "Blue-points" => 0, "Red-points" => 0, "Lobby-coords" => array(), "Point-announce-interval" => 2, "Remaining-time" => 15 )); $this->config = new Config($this->api->plugin->configPath($this). "blue.yml", CONFIG_YAML, array()); $this->config = new Config($this->api->plugin->configPath($this). "red.yml", CONFIG_YAML, array()); console(FORMAT_GREEN. "[INFO] CTFplugin loaded!"); } public function handler($data, $event) { switch ($event) { case "player.join": console("Player: " . $data->username . " joined!"); break; case "player.spawn": $info = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $reddata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "red.yml"); $bluedata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "blue.yml"); $user = $data->username; if (array_key_exists($user, $reddata) or array_key_exists($user, $bluedata)) { //remove this, teleport them to their base, not to lobby if (isset($info["Lobby-coords"][0])) { $x = $data["Lobby-coords"][0]; $y = $data["Lobby-coords"][1]; $z = $data["Lobby-coords"][3]; $level = $data["Lobby-coords"][4]; $this->api->console->run("tp " . $user . " " . $x . " " . $y . " " . $z); } } break; case "player.block.break": $info = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $reddata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "red.yml"); $bluedata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "blue.yml"); if($data["item"]->getID() === 35 || $data["item"]->getID() === 23){ $target = $data["block"]; $tx = $target->x; $ty = $target->y; $tz = $target->z; $tl = $target->level->getName(); $rx = $info["Red-flag"][0]; $ry = $info["Red-flag"][1]; $rz = $info["Red-flag"][3]; $rlevel = $info["Red-flag"][4]; $bx = $info["Blue-flag"][0]; $by = $info["Blue-flag"][1]; $bz = $info["Blue-flag"][3]; $blevel = $info["Blue-flag"][4]; $user = $data->username; if ($tx === $bx || $ty === $by || $tz === $bz || $tl === $blevel or $tx === $rx || $ty === $ry || $tz === $rz || $tl === $rlevel) { if (array_key_exists($user, $reddata)){ $this->api->chat->broadcast("[RED]" . $user . " broke the blue team's flag!"); } else if (array_key_exists($user, $bluedata)) { $this->api->chat->broadcast("[BLUE]" . $user . " broke the red team's flag!"); } else if ($tl != $blevel or $tl != $rlevel) { return true; } } else return false; } break; case "player.block.place": $user = $data->username; $info = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $reddata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "red.yml"); $bluedata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "blue.yml"); if($data["item"]->getID() === 35 || $data["item"]->getID() === 23){ $target = $data["block"]; $tx = $target->x; $ty = $target->y; $tz = $target->z; $tl = $target->level->getName(); $rx = $info["Red-return"][0]; $ry = $info["Red-return"][1]; $rz = $info["Red-return"][3]; $rlevel = $info["Red-return"][4]; $bx = $info["Blue-return"][0]; $by = $info["Blue-return"][1]; $bz = $info["Blue-return"][3]; $blevel = $info["Blue-return"][4]; if ($tx === $bx || $ty === $by || $tz === $bz || $tl === $blevel) { if (array_key_exists($user, $reddata)) { $this->api->chat->broadcast("The RED team returned the flag! +1 point!"); $redpoints = $info["Red-points"]; $redpoints = $redpoints + 1; $this->api->plugin->writeYAML($this->api->plugin->configPath($this)."CTF.yml", $redpoints); } else return false; } else if ($tx === $rx || $ty === $ry || $tz === $rz || $tl === $rlevel) { if (array_key_exists($user, $bluedata)){ $this->api->chat->broadcast("The BLUE team returned the flag +1 point"); $bluepoints = $info["Blue-points"]; $bluepoints = $bluepoints + 1; $this->api->plugin->writeYAML($this->api->plugin->configPath($this)."CTF.yml", $bluepoints); } else return false; } } case "player.interact": $info = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $reddata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "red.yml"); $bluedata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "blue.yml"); $target1=$data["targetentity"]->class; if($target1=="1") { $target=$data["targetentity"]->player->username; $player=$data['entity']->player->username; { if (array_key_exists($player, $bluedata) || array_key_exists($target, $bluedata)) { //attacker is on same team as target (blue) $this->api->chat->sendTo(false, "[CTF] You cannot attack your own teammate!", $player); return false; } else if (array_key_exists($player, $reddata) || array_key_exists($target, $reddata)) { $this->api->chat-sendTo(false, "[CTF] You cannot attack your own teammate!", $player); } } } break; } } public function command($cmd, $args, $issuer) { switch($cmd){ case "lobbyset": $data = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $x = round($issuer->entity->x); $y = round($issuer->entity->y); $z = round($issuer->entity->z); $level = $issuer->level->getName(); $data["Lobby-coords"] = array($x, $y, $z, $level); $this->api->plugin->writeYAML($this->api->plugin->configPath($this)."CTF.yml", $data); return "[CTF] CTF lobby set to: " . $x . " " . $y . " " . $z . "!"; break; case "base": $user = $issuer->username; $info = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $reddata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "red.yml"); $bluedata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "blue.yml"); $rx = $info["Red-base"][0]; $ry = $info["Red-base"][1]; $rz = $info["Red-base"][3]; $rlevel = $info["Red-base"][4]; $bx = $info["Blue-base"][0]; $by = $info["Blue-base"][1]; $bz = $info["Blue-base"][3]; $blevel = $info["Blue-base"][4]; $bluetotal = count($bluedata); $redtotal = count($reddata); if (isset($rx) or isset($bx)) { continue; } else return "A base is has not been set."; if (array_key_exists($user, $reddata) or array_key_exists($user, $bluedata)){ return "[CTF] You are already on a team, do /warpbase to go to your base!"; } else { if ($redtotal > $bluetotal){ $team = "blue"; $bluedata[$user] = array(); $this->api->plugin->writeYAML($this->api->plugin->configPath($this). "blue.yml", $bluedata); } else if ($bluetotal > $redtotal) { $team = "red"; $reddata[$user] = array(); $this->api->plugin->writeYAML($this->api->plugin->configPath($this). "red.yml", $reddata); } else { $rteam = array_rand(array("Red", "Blue")); if ($rteam === "Red") { $team = "Red"; $reddata[$user] = array(); $this->api->plugin->writeYAML($this->api->plugin->configPath($this). "red.yml", $reddata); } else { $team = "Blue"; $bluedata[$user] = array(); $this->api->plugin->writeYAML($this->api->plugin->configPath($this). "blue.yml", $bluedata); } } } if ($team === "Blue") { $this->api->console->run("clearinventory " . $user); $this->api->console->run("give " . $user . "iron_helmet 1"); $this->api->console->run("give " . $user . " iron_leggings 1"); $this->api->console->run("give " . $user . " iron_boots 1"); $this->api->console->run("give " . $user . " leather_tunic 1"); $this->api->console->run("give " . $user . " bread 3"); $this->api->console->run("give " . $user . " stone_sword 1"); $this->api->console->run("give " . $user . " flint_and_steel 1"); $this->api->chat->broadcast("[CTF] Player: " . $user . " joined the BLUE team!"); $this->api->console->run("tp" . $user . " w:" . $blevel); $this->api->console->run("tp " . $user . " " . $bx . " " . $by . " " . $bz); return "You joined the BLUE team!"; } else if ($team === "Red") { $this->api->console->run("clearinventory " . $user); $this->api->console->run("give " . $user . "iron_helmet 1"); $this->api->console->run("give " . $user . " chain_leggings 1"); $this->api->console->run("give " . $user . " chain_boots 1"); $this->api->console->run("give " . $user . " leather_tunic 1"); $this->api->console->run("give " . $user . " bread 3"); $this->api->console->run("give " . $user . " stone_sword 1"); $this->api->console->run("give " . $user . " flint_and_steel 1"); $this->api->chat->broadcast("[CTF] Player: " . $user . " joined the RED team!"); $this->api->console->run("tp" . $user . " w:" . $rlevel); $this->api->console->run("tp " . $user . " " . $rx . " " . $ry . " " . $rz); return "You joined the RED team!"; } break; case "setb": if ($params[0] === "s") { $data = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $x = round($issuer->entity->x); $y = round($issuer->entity->y); $z = round($issuer->entity->z); $level = $issuer->level->getName(); $data["Blue-base"] = array($x, $y, $z, $level); $this->api->plugin->writeYAML($this->api->plugin->configPath($this)."CTF.yml", $data); return "[CTF] Blue spawn set to: " . $x . " " . $y . " " . $z . "!"; } else if ($params[0] === "f") { $data = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $x = round($issuer->entity->x); $y = round($issuer->entity->y); $z = round($issuer->entity->z); $level = $issuer->level->getName(); $data["Blue-flag"] = array($x, $y, $z, $level); $this->api->plugin->writeYAML($this->api->plugin->configPath($this)."CTF.yml", $data); return "[CTF] Blue flag set to: " . $x . " " . $y . " " . $z . "!"; } else if ($params[0] === "r") { $data = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $x = round($issuer->entity->x); $y = round($issuer->entity->y); $z = round($issuer->entity->z); $level = $issuer->level->getName(); $data["Blue-return"] = array($x, $y, $z, $level); $this->api->plugin->writeYAML($this->api->plugin->configPath($this)."CTF.yml", $data); return "[CTF] Blue return point set to: " . $x . " " . $y . " " . $z . "!"; } else { return "Usage: /setb [f] or [r] or [s]"; } break; case "setr": if ($params[0] === "s") { $data = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $x = round($issuer->entity->x); $y = round($issuer->entity->y); $z = round($issuer->entity->z); $level = $issuer->level->getName(); $data["Red-base"] = array($x, $y, $z, $level); $this->api->plugin->writeYAML($this->api->plugin->configPath($this)."CTF.yml", $data); return "[CTF] Red spawn set to: " . $x . " " . $y . " " . $z . "!"; } else if ($params[0] === "f") { $data = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $x = round($issuer->entity->x); $y = round($issuer->entity->y); $z = round($issuer->entity->z); $level = $issuer->level->getName(); $data["Red-flag"] = array($x, $y, $z, $level); $this->api->plugin->writeYAML($this->api->plugin->configPath($this)."CTF.yml", $data); return "[CTF] Red flag set to: " . $x . " " . $y . " " . $z . "!"; } else if ($params[0] === "r") { $data = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $x = round($issuer->entity->x); $y = round($issuer->entity->y); $z = round($issuer->entity->z); $level = $issuer->level->getName(); $data["Red-return"] = array($x, $y, $z, $level); $this->api->plugin->writeYAML($this->api->plugin->configPath($this)."CTF.yml", $data); return "[CTF] Red return point set to: " . $x . " " . $y . " " . $z . "!"; } else { return "Usage: /setr [f] or [r] or [s]"; } break; case "warpbase": $user = $issuer->username; $info = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $reddata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "red.yml"); $bluedata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "blue.yml"); $rx = $info["Red-base"][0]; $ry = $info["Red-base"][1]; $rz = $info["Red-base"][3]; $rlevel = $info["Red-base"][4]; $bx = $info["Blue-base"][0]; $by = $info["Blue-base"][1]; $bz = $info["Blue-base"][3]; $blevel = $info["Blue-base"][4]; if (array_key_exists($user, $reddata)) { $this->api->console->run("tp w: " . $rlevel); $this->api->console->run("tp " . $user . " " . $rx . " " . $ry . " " . $rz); } else if (array_key_exists($user, $bluedata)) { $this->api->console->run("tp w: " . $blevel); $this->api->console->run("tp " . $user . " " . $bx . " " . $by . " " . $bz); } else return "You are not a CTF player, do /base to join a ctf game!"; break; } } public function points(){ $info = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $timeleft = $info["Remaining-time"]; $lefttime = $timeleft - 2; $info["Remaining-time"] = $lefttime; $this->api->plugin->writeYAML($this->api->plugin->configPath($this). "CTF.yml", $info); $redpoints = $info["Red-points"]; $bluepoints = $info["Blue-points"]; $this->api->chat->broadcast("Scores: " . "RED returns:" . $redpoints . " BLUE returns:" . $bluepoints); $this->api->chat->broadcast("Remaining time in game: " . $lefttime . "mins."); sleep(20); $this->api->chat->broadcast("Do /base to join the CTF game!"); sleep(10); } public function EndGame (){ $info = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "CTF.yml"); $redpoints = $info["Red-points"]; $bluepoints = $info["Blue-points"]; $reddata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "red.yml"); $bluedata = $this->api->plugin->readYAML($this->api->plugin->configPath($this). "blue.yml"); if ($bluepoints > $redpoints) { $this->api->chat->broadcast("The BLUE team won the match!"); $this->api->chat->broadcast("Scores: BLUE: " . $bluepoints . " RED: " . $redpoints); } else if ($redpoints > $bluepoints) { $this->api->chat->broadcast("The RED team won the match!"); $this->api->chat->broadcast("Scores: BLUE: " . $bluepoints . " RED: " . $redpoints); } else { $this->api->chat->broadcast("The match ended in a tie!"); } $bluedata = array(); $reddata = array(); $this->api->chat->broadcast("If you want to join the next match, do /base!"); $this->api->plugin->writeYAML($this->api->plugin->configPath($this). "blue.yml", $bluedata); $this->api->plugin->writeYAML($this->api->plugin->configPath($this). "red.yml", $reddata); $info["Remaining-time"] = 15; $this->api->plugin->writeYAML($this->api->plugin->configPath($this). "CTF.yml", $info); } public function __destruct() { } }
this the code for new minigame called CTF try it out
note:its for pocketmine only