Closed ghost closed 6 years ago
just make $name an array
$players = [];
foreach($player->getServer()->getOnlinePlayers() as $onlinePlayer){
if($onlinePlayer !== $player){
$players[] = $onlinePlayer->getName();
}
}
And put $players
to dropdown
<?php
declare(strict_types=1);
namespace NS;
use Frago9876543210\EasyForms\EasyForms;
use Frago9876543210\EasyForms\elements\custom\Dropdown;
use Frago9876543210\EasyForms\forms\CustomForm;
use pocketmine\Player;
use pocketmine\utils\TextFormat;
class ChoosePlayer extends CustomForm{
public function __construct(array $players){
parent::__construct("Choose a player", [
new Dropdown("Player", $players)
]);
}
public function onSubmit(Player $player, $response) : void{
parent::onSubmit($player, $response);
/** @var Dropdown $dropdown */
$dropdown = $this->popElement();
if(($target = $player->getServer()->getPlayer($targetName = $dropdown->getSelectedOption())) instanceof Player){
//TODO
}else{
$player->sendMessage(TextFormat::YELLOW . "Player leave");
}
}
}
How do i add each player to drop down