Create a key in $arenas[] and reset it to 0 when the game ends. The key will be used for incrementing spawn keys in the array. PHP: //You will need to define $this->arenas["sw-1"]["increments"] = 0;public function joinToArena(Player $p){ //Your code.. $spawns = $this->arenas["sw-1"]; $spawnno = ++$spawns["increments"]; $spawns = $spawns[$spawnno."spawn"] ?? null;//1spawn, 2spawn... etc. if ($spawns === null) { throw new \OutOfRangeException("Spawn '".$spawnno."spawn' is not set in arenas. Could not teleport player to '".$spawnno."spawn'."); } else { $p->teleport($spawn); }}//When game ends, you will need to reset the increments by doing//$this->arenas["sw-1"]["increments"] = 0;
Thank you but after player join arena he is teleported to waiting lobby where wait until game start and then is teleported to spawn so joinToArena function only add player to my waiting lobby