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. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    how can i do foreach Online players it add a button in the UI and then when i click that button it store the name of the player in public Variable .
    PHP:
        public function test($player) {
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $player$data){
                if(
    $data === null){
                    return;
                }
                else {
                      
    //What should i do here ?
               
    });
            
    $form->setTitle("§7test§r");
            
    $form->setContent("§aTesT ");
             foreach(
    $this->getServer()->getOnlinePLayers as $f){
                 if(!
    $this->getServer()->getPlayerExact($f) == null){
                     
    $form->addButton("§e".$f ." \n» §7(§aOnline§7) §e«§r");
                 }
            }
            
    $form->addButton("§0Back§r");
            
    $form->sendToPlayer($player);
            return 
    $form;
        }
     
    Last edited: May 22, 2020
  2. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    help me pls
     
  3. TheOriginDevelopment

    TheOriginDevelopment Creeper

    Messages:
    5
    GitHub:
    theorigindeveloppement
    try with
    PHP:
        public function test($player) {
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $player$data){
                if(
    $data === null){
                    return;
                }
                else {
          
               });
            
    $form->setTitle("§7test§r");
            
    $form->setContent("§aTesT ");
             foreach(
    $this->getServer()->getOnlinePlayers as $f){
                 if(
    $f instanceof Player){
                     
    $form->addButton("§e".$f->getName() ." \n» §7(§aOnline§7) §e«§r");
                 }
            }
            
    $form->addButton("§0Back§r");
            
    $form->sendToPlayer($player);
            return 
    $form;
        }
     
    Last edited: May 22, 2020
    aminozomty likes this.
  4. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    TheOriginDevelopment
    you didn't understand what i want:
    When i open this UI it should add buttons foreach all online members and when i click any button it should store the name of that a player in a public variable
     
  5. TheOriginDevelopment

    TheOriginDevelopment Creeper

    Messages:
    5
    GitHub:
    theorigindeveloppement
    Oh okey srry try that :
    PHP:
        public function test($player) {
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $player$data){
                if(
    $data === null){
                    return;
                }
                else {
           switch(
    $data){     
               default:
       
    $players $this->getServer()->getOnlinePlayers();                
        
    $this->player array_slice($players$data);              //$this->player = the player you clicked in the menu
              
    break;
    }
               });
            
    $form->setTitle("§7test§r");
            
    $form->setContent("§aTesT ");
             foreach(
    $this->getServer()->getOnlinePlayers as $f){
                 if(
    $f instanceof Player){
                     
    $form->addButton("§e".$f->getName() ." \n» §7(§aOnline§7) §e«§r");
                 }
            }
            
    $form->addButton("§0Back§r");
            
    $form->sendToPlayer($player);
            return 
    $form;
        }
     
  6. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
  7. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    it didn't work TheOriginDevelopment.
    i want the name of the player not the player and if i will use getName() it will not work because we can't call the function getName() on an array
     
    Last edited: May 22, 2020
  8. TheOriginDevelopment

    TheOriginDevelopment Creeper

    Messages:
    5
    GitHub:
    theorigindeveloppement
    for get the name of player try array_shift($this->player)->getName()
     
  9. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    ok i will try
     
  10. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    didn't work
     
  11. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    i'm sorry TheOriginDevelopment .
    i know what's the problem with my work .when you do getOnlinePlayers but me i was using config and in the config there was a name of a player not a player .but can you help me please
    this is my real work
    PHP:
    public function TestUI($player) {
            
    $playerDis $player->getPlayer();
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $player$data){
                if(
    $data === null){
                    return;
                }
                else{
                    
    $config = new Config($this->getDataFolder().'/players/'.$player->getName().".yml"Config::YAML);
                    
    $this->TestTwoUI($player);
                    
    $players $config->get("test");
                    
    $this->test array_slice($players$data);
                }
            });
            
    $config = new Config($this->getDataFolder().'/players/'.$player->getName().".yml"Config::YAML);
            
    $form->setTitle("§7Test§r");
            
    $form->setContent("§aTest: ");
            if(empty(
    $config->get("test"))){
                
    $form->setContent("§4No one in the config!");
            }
            else{
                foreach(
    $config->get("test") as $t){ 
                    if(!
    $this->getServer()->getPlayerExact($t) == null){
                        
    $form->addButton("§e".$t ." \n» §7(§aOnline§7) §e«§r");
                    }
                    else{
                        
    $form->addButton("§e".$t ." \n» §7(§cOffline§7) §e«§r");
                    }
                }
            
    $form->addButton("§0Back§r");
            
    $form->sendToPlayer($player);
            return 
    $form;
        }
            }
    But it doesn't work correctly.
     
    Last edited: May 23, 2020
  12. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    Can anyone help me now ?
     
  13. HiToLaKhanh

    HiToLaKhanh Spider Jockey

    Messages:
    25
    GitHub:
    HiToLaKhanh
    did you mean this:
     
  14. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    no i don't want in a dropdown i want it to be like buttons and i don't need online players because i'm using config now that store a name of a player when i do a command and when i click that button it store the name of a player in a private variable understand HiToLaKhanh ?
    any Otherone Can help
     
    Last edited: May 23, 2020
  15. HiToLaKhanh

    HiToLaKhanh Spider Jockey

    Messages:
    25
    GitHub:
    HiToLaKhanh
    oh, i see
     
  16. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
    Can someone help me now ?
    please i don't know how to do that
     
  17. HiToLaKhanh

    HiToLaKhanh Spider Jockey

    Messages:
    25
    GitHub:
    HiToLaKhanh
    use in_array dude
     
  18. aminozomty

    aminozomty Silverfish

    Messages:
    19
    GitHub:
    aminozomty
  19. HiToLaKhanh

    HiToLaKhanh Spider Jockey

    Messages:
    25
    GitHub:
    HiToLaKhanh
    no i am wrong
     
  20. HiToLaKhanh

    HiToLaKhanh Spider Jockey

    Messages:
    25
    GitHub:
    HiToLaKhanh
    lemme check again
     
  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.