Hello, I come back because I think my last thread was not precise enough... First, I 'll explain what I want to do and then I'll show you my code (which obviously doesn't work...). I would like teleport 8 connected players through a command. Each player must be different ... (this is what I can not do). My code : PHP: public function getPlayers(){ $Online = $this->getServer()->getOnlinePlayers(); $rand1 = array_rand($Online); $rand2 = array_rand($Online); $rand3 = array_rand($Online); $rand4 = array_rand($Online); $rand5 = array_rand($Online); $rand6 = array_rand($Online); $rand7 = array_rand($Online); $rand8 = array_rand($Online); list($rand1, $rand2, $rand3, $rand4, $rand5, $rand6, $rand7, $rand8) = $this->verifyRand($rand1, $rand2, $rand3, $rand4, $rand5, $rand6, $rand7, $rand8); if(isset($Online[$rand1]) && isset($Online[$rand2]) && isset($Online[$rand3]) && isset($Online[$rand4]) && isset($Online[$rand5]) && isset($Online[$rand6]) && isset($Online[$rand7]) && isset($Online[$rand8])){ $player1 = $Online[$rand1]; $player2 = $Online[$rand2]; $player3 = $Online[$rand3]; $player4 = $Online[$rand4]; $player5 = $Online[$rand5]; $player6 = $Online[$rand6]; $player7 = $Online[$rand7]; $player8 = $Online[$rand8]; $this->launchTournament($player1, "Arene1"); $this->launchTournament($player2, "Arene1"); $this->launchTournament($player3, "Arene2"); $this->launchTournament($player4, "Arene2"); $this->launchTournament($player5, "Arene3"); $this->launchTournament($player6, "Arene3"); $this->launchTournament($player7, "Arene4"); $this->launchTournament($player8, "Arene4"); } } public function verifyRand($r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8){ $rand = [$r1 => true, $r2 => true, $r3 => true, $r4 => true, $r5 => true, $r6 => true, $r7 => true, $r8 => true]; if(count($rand) <= 7){ if(count($this->getServer()->getOnlinePlayers()) > 7){ $r1 = array_rand($this->getServer()->getOnlinePlayers()); $r2 = array_rand($this->getServer()->getOnlinePlayers()); $r3 = array_rand($this->getServer()->getOnlinePlayers()); $r4 = array_rand($this->getServer()->getOnlinePlayers()); $r5 = array_rand($this->getServer()->getOnlinePlayers()); $r6 = array_rand($this->getServer()->getOnlinePlayers()); $r7 = array_rand($this->getServer()->getOnlinePlayers()); $r8 = array_rand($this->getServer()->getOnlinePlayers()); return $this->verifyRand($r1, $r2, $r3, $r4, $r5, $r6, $r7, $r8); } }else{ return $rand; } } Sorry for my bad english, I am French...
PHP: public function getTeam($size = 8) : array { $team = array_chunk($this->getServer()->getOnlinePlayers(), $size)[0]; shuffle($team); return $team;}$team = $this->getTeam();foreach($team as $i => $p) $this->launchTournament($p, "Arene" . ($i + 1) ); Spoiler: test code @ phpfiddle.com Code: class Server { public function getOnlinePlayers() { return ["Steve", "Bob", "Alex", "Jake", "Micheal", "Jorge", "Olivia", "Andreas", "Jim", "Tom", "Bill"]; } } class Test { public function getServer() { return new Server; } public function getTeam($size = 8) { $team = array_chunk($this->getServer()->getOnlinePlayers(), $size)[0]; shuffle($team); return $team; } public function entry() { $team = $this->getTeam(); foreach($team as $i => $p) $this->launchTournament($p, "Arene" . ($i + 1) ); } public function launchTournament($player, $arena) { print "$player entering $arena... </br>"; } } $t = new Test(); $t->entry();
Just a reminder, array_rand returns a KEY, not the value. This means that if you want to get a random value from the array, this is the proper (but not only) way. PHP: $array[array_rand($array)]; For more info read the documentation on array_rand @ php.net
Hello, I tested with 8 players and it teleports players on eight arenas ... But it must have 2 players per arena on the first 4 arenas . Player 1 and 2 => Arene1 Player 3 and 4 =>Arene2 Player 5 and 6 => Arene3 Player 7 and 8 => Arene4
Implausible to tell that from your code and content of this thread. As your slaves we will help you to change few bytes of code for you, I guess it's extremely hard for you. *cough* *cough*
Hello, Hello, I was helped by Ad5001 ... I try to make very simple so that you understand my messages. I did not want to be nasty in my last post , sorry... I am a novice in php... You 've never been ? Thank you for your answer , you are very nice to help me...
You never start writing before learning to read, it's really important that you learn php at first. Appreciate the resources you can find on web for free.
Maybe somone should introduce a plugin enabling this, like BetterTeleport or something like that (I just made the name up) At last I have learnt something. Probably wont again in a month