I am working on SkyWars plugin for my minigame server , but I have not idea how to do this. I have lots of tries to do this I saved spawns to array etc, but not sucesfull. Can everyone give me example for this?
PHP: /** @var Arena $areny */public $areny = [];public function getNewArena($name){$a = new Arena($name, $this);$this->areny[$name] = $a;
The active players in the arena class is probably an array, just foreach them and Add them to the queue again?
I have stored spawns now how to teleport every player to another spawn?? PHP: $this->arenas["sw-1"] = ['lobby" => new Vector3(124, 20, 78), '1sign' => new Vector3(488, 21, 493), '1spawn' => new Vector3(0, 10, 5), '2spawn' => new Vector3(0, 10, -1) ];
You are insecure about sharing your relevant code, how can we help you when we don't even know your Arena class's structure?
PHP: <?phpnamespace SkyWars\Game;use pocketmine\Player;use pocketmine\Server;use pocketmine\event\Listener;use pocketmine\utils\Config;use pocketmine\math\Vector3;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\event\player\PlayerQuitEvent;use SkyWars\Scheduler\GameTask;use SkyWars\SkyWars;class Arena implements Listener{ /** @var Player[] */ public $players = []; /** @var Player[] */ public $spectators = []; public $starting = false; public $game = 0; public $ending = false; /** @var GameTask $task */ public $task; public $winnerName; public $mainData; public $joinable = true; public $plugin; public $id; public function __construct($id, SkyWars $plugin){ $this->id = $id; $this->plugin = $plugin; $this->mainData = $plugin->arenas[$id]; $this->enableScheduler(); } public function enableScheduler(){ $this->plugin->getServer()->getScheduler()->scheduleRepeatingTask($this->task = new GameTask($this), 20); } public function stopGame(){ foreach(array_merge($this->players, $this->spectators) as $p){ $p->teleport(Server::getInstance()->getDefaultLevel()->getSafeSpawn()); $p->getInventory()->clearAll(); $p->setHealth(20); $p->setFood(20); } $this->unsetAll(); } public function unsetAll(){ $this->spectators = []; $this->players = []; $this->joinable = true; $this->starting = false; $this->task->startTime = 60; $this->game = 0; $this->winnerName = null; $this->ending = false; } public function onInteract(PlayerInteractEvent $e){ $b = $e->getBlock(); // if($b->x == $this->mainData["sign"]->x and $b->z == $this->mainData["sign"]->z and $y = $this->mainData["sign"]->y){ $this->joinToArena($e->getPlayer()); // } } public function getAllPlayers(){ foreach($this->players as $p){ return $p; } } public function onQuit(PlayerQuitEvent $e){ $p = $e->getPlayer(); $this->onPlayerQuit($p); } public function checkAlive(){ if($this->ending == false){ if(count($this->players) == 1){ if($this->ending == false) { $this->winnerName = $this->getAllPlayers()->getName(); foreach ($this->players as $p){ $p->addTitle("§l§6VICTORY!", "§7You were the last man standing!"); } $this->ending = true; foreach(array_merge($this->spectators, $this->players) as $p){ $p->sendMessage("§l§a-----------------------------§r\n§l§7 SkyWars §r\n §eWinner - " . $this->winnerName); }} } } } public function onPlayerQuit(Player $p){ if(isset($this->players[strtolower($p->getName())])){ unset($this->players[strtolower($p->getName())]); } if(isset($this->spectators[strtolower($p->getName())])){ unset($this->spectators[strtolower($p->getName())]); } } public function startGame(){ $this->starting = false; $this->joinable = false; $this->game = 1; foreach($this->players as $p){ $p->addTitle("test"); $p->getInventory()->clearAll();} } public function joinToArena(Player $p){ if($this->joinable == false){ $this->spectators[strtolower($p->getName())] = $p; $p->sendMessage("Joining as spectator"); return false; } if(count($this->players) >= 12){ $p->sendMessage("Arena full / Check task"); } $this->players[strtolower($p->getName())] = $p; $p->getInventory()->clearAll(); $p->sendMessage("Joining arena $this->id test"); $this->checkAll(); } public function checkAll(){ if(count($this->players) > 1 and $this->game == 0){ $this->starting = true; } if(count($this->players) >= 12 and $this->game == 0/*TODO Check for time*/){ //Short time } }}