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

Get all players name ForamAPI.

Discussion in 'Development' started by armagadon159753, Nov 8, 2017.

  1. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Hi the developers.
    I would like to do a plugin with FormAPI but here I am blocking.
    how can I get the name of all online players in buttons

    PHP:
    public function mainFrom($player){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $event, array $data){
            
    $player $event->getPlayer();
            
    $result $data[0];
            if(
    $result === null){
            }
            switch(
    $result){                           
                case 
    0:
                break;
                case 
    1:
                break;
                }                   
            });                   
            
    $form->setTitle("--= " "AdminUI" " =--");
            
    $form->setContent("Make your choose.");
            foreach(
    $this->getServer()->getOnlinePlayers() as $online){
                
    $name $online->getName();
                
    $form->addButton($name);
                
    $form->sendToPlayer($player);
            }
        }
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Don't use $form->sendToPlayer() inside of foreach() loop
     
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Thx you but i have an other issu.
    How get ne player name who was target
     
  4. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Do var_dump($data);
    You have to check for result number which is not null
     
    jasonwynn10 and QuiverlyRivalry like this.
  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.