On join to mini game 1 player all done, but on join two players server stopped. Sorry for bad english, I'm from Russia. We have a completely different structure the sentences. PHP: public function GameJoin(PlayerInteractEvent $e){ $p = $e->getPlayer(); $b = $e->getBlock(); $item = $p->getInventory()->getItemInHand(); if($item !== null && $this->players < 8){ if($b->getId() == 133){ if($item->getId() == 263){ $p->getInventory()->clearAll(); $this->give($p, 1); } if($item->getId() == 265){ $p->getInventory()->clearAll(); $this->give($p, 2); } if($item->getId() == 266){ $p->getInventory()->clearAll(); $this->give($p, 3); } if($item->getId() == 341){ $p->getInventory()->clearAll(); $this->give($p, 4); } if($item->getId() == 348){ $p->getInventory()->clearAll(); $this->give($p, 5); } if(!($item->getId() == 263 or $item->getId() == 265 or $item->getId() == 266 or $item->getId() == 341 or $item->getId() == 348)){ $p->sendTip("§b Вы не выбрали класс!"); }else{ $this->setGame($p);$this->getLogger()->info("set game $p"); } } } else { $p->sendTip("§6 Арена полная!"); } }public function setGame($p){ if($this->gameStatus==0 && $this->players >= 1){ $this->gameStatus=1; } if($this->gameStatus !== 2){ //if($this->players !== 8){ $this->setPos($p);$this->getLogger()->info("set pos $p"); //} } } public function setPos($player){ $name = $player->getName(); $pos = array("1","2","3","4","5","6","7","8"); $rand = array_rand($pos); $r = $pos[$rand]; $n = $this->info["pos$r"]["name"]; $p = $this->info["pos$r"]["pos"]; $a = $this->info["pos$r"]["a"]; if($a == "0"){ $this->info["pos$r"] = array("name"=>"$name", "pos"=>"$r", "a"=>"1"); $playername = $this->info["pos$r"]["name"]; $a_pos = $this->info["pos$r"]["a"]; $this->spawn($player, $r);$this->getLogger()->info("spawn $p"); }else{ $this->setPos($player);$this->getLogger()->info("set pos 2 $p"); } } public function spawn($p, $pos){ if($pos == !null){$this->getLogger()->info("spawned $p succeed"); $p->teleport(Server::getInstance()->getLevelByName("SuperSmashMobs")->getSafeSpawn()); if($pos == 1){ $p->teleport(new Vector3(135, 32, 103)); } if($pos == 2){ $p->teleport(new Vector3(135, 33, 139)); } if($pos == 3){ $p->teleport(new Vector3(144, 33, 161)); } if($pos == 4){ $p->teleport(new Vector3(111, 33, 159)); } if($pos == 5){ $p->teleport(new Vector3(89, 33, 120)); } if($pos == 6){ $p->teleport(new Vector3(114, 32, 85)); } if($pos == 7){ $p->teleport(new Vector3(157, 30, 75)); } if($pos == 8){ $p->teleport(new Vector3(172, 35, 120)); } } }
Use this is more better PHP: if(count($this->array) == 1){# teleport to pos1}if(count($this->array) == 2){# teleport to pos2}
This isn't going to solve your problem but on PlayerInteractEvent use elseif instead of if multiple times it's faster.
Your code is very bad, it wastes more memory and runs slower. Why are you choosing a position with mt_rand(), there is a big chance that the players will join the same position, did you know that? What I really suggest is make an array of the positions, make a variable with the amount of positions, make an array to save players in-game (players in-game array is optional). I'll show an example here, it is much easier to code it than to explain it: PHP: public $pn = 12;//amount of positionspublic $positions = [new Vector3(99,99,99)];//vector 3 positionspublic function setPlayer(Player $p){//Check if player already joined logic here and return//Else if hasn't joinedif($this->pn < 0){return;//if full don't join}//Else join$pos = $this->positions[$this->pn];--$this->pn;$p->teleport($pos);}//Reset functionpublic function reset(){$this->pn = 24;//Other stuff}
Thanks, but this code work: PHP: $p->teleport(new Vector3(135, 33, 139)); and this code don't work: PHP: $players = count($this->getServer()->getLevelByName("SuperSmashMobs")->getPlayers())+1;$pos = $this->pos[$players];$r = $p->teleport(new Vector3($pos));$this->getLogger()->info("teleport(new Vector3($pos));");