when I do command /armor, get random of one player and set Armor automatically. How can? here is the code that I tried PHP: function setArmor(ArmorInventory $aie, $SA){ $SA->getArmorInventory()->setHelmet(Item::get(310, 0, 1)); $SA->getArmorInventory()->setChestplate(Item::get(311, 0, 1)); } public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool { $command = $command->getName(); $player = $sender->getPlayer(); $name = $sender->getName ();if($command == "armor"){ $rp = $this->D["Players"][]; $vrp = array_rand($rp,1);setArmor("$vrp"); } }
You can get a random player by getting all online players, and then using array_rand. Try this code (it was sort of rushed so...): PHP: public function setArmor(Player $player){ $player->getArmorInventory()->setHelmet(); $player->getArmorInventory()->setChestplate(); } public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool { $cmd = $command->getName(); if($cmd == "armor"){ $players = $this->getServer()->getOnlinePlayers(); $player = $players[array_rand($players)]; $this->setArmor($player); return true; } } I tried not using switch($command->getName()) for your convince