1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved FormApi Help please

Discussion in 'Development' started by aminozomty, May 22, 2020.

  1. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    Let's me help you, so you want an ui display all player had joined the server but not the dropdown right
     
  2. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    PHP:
    public function sendListUI(Player $player){
            
    //$this->formapi is the FormAPI plugin xD
            
    $form $this->formapi->createSimpleForm(function (Player $player$data null){
                
    $target $data;
                if(
    $target === null) return true;
                
    //...
                /**
                 * $playername is the name of the player in the button
                 * In this function, $target is the name of the button which had clicked
                 * Also i just can help to here, i don't know what will you gonna do!
                */
            
    });
            
    $form->setTitle("Epic title");
            
    $form->setContent("More epic lol");
            
    $path $this->getServer()->getDataPath() . "players/";
            foreach(
    array_diff(scandir($path), array('.''..')) as $f){
                
    $fe strtolower(pathinfo($path $fPATHINFO_EXTENSION));
                if(
    $fe == "dat"){
                    
    $playername str_replace("." $fe''$f);
                    
    $form->addButton($playername, -1""$playername);
                }
            }
            
    $form->sendToPlayer($player);
        }
     
    HiToLaKhanh likes this.
  3. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    thank you very much that's not the thing that i want but it helped me alot.
     
  4. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    Ok, no problem my pal
     
  5. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    You're welcome
    PHP:
    /** @var Player */
    private $selectedPlayer;

    public function 
    sendOnlinePlayersForm(Player $player): void {
        
    $onlinePlayers Server::getInstance()->getOnlinePlayers();

        
    $form = new SimpleForm(function(Player $player, ?int $result) use ($onlinePlayers) {
            if(
    $result !== null) {
                
    $this->selectedPlayer $onlinePlayers[$result];
            }
        });
       
        foreach(
    $onlinePlayers as $onlinePlayer) {
            
    $form->addButton($onlinePlayer->getName());
        }
        
    $player->sendForm($form);
    }
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.