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

Solved FormAPI Repair

Discussion in 'Development' started by dbcooper, Oct 6, 2018.

  1. dbcooper

    dbcooper Spider Jockey

    Messages:
    32
    GitHub:
    dbcooper
    Hello,

    I’ve written some code for a repair ui, but it doesn’t work. I’ve contacted some other devs and they don’t know whats up with it either. Any help is appreciated...

    PHP:
     public function repairForm($player){
        
    $options = [];
        foreach (
    $player->getInventory()->getContents() as $key => $content){
            if(
    $content instanceof Durable$options[$key] = $content->getName();
        }
        
    $form $this->plugin->createCustomForm(function (Player $player, array $data) use ($options) {
                if(isset(
    $data[1])){
                
    var_dump([array_keys($options)]);
                        
    $slot $options[array_keys($options)[$data[1]]];
                }
        });
        
    $form->setTitle("§c--= §l§dBlacksmith§r§c =--");
        
    $form->addLabel("Select an item below for repairing.");
        
    $form->addDropdown("Select an item below that youd like to repair."$options);
        
    $form->sendToPlayer($player);
    }
    }
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    "it doesn't work" isn't certainly the most precise description of a problem.
    How does it not work? Does it display an error? (If so, what does it say?) Does it not open the Form? Does the Form not respond?
     
  3. Aericio

    Aericio Slime

    Messages:
    99
    GitHub:
    aericio
    [​IMG]

    (I don't have access to the plugin, he just sent this earlier in Discord.)
     
    XenialDan and HimbeersaftLP like this.
  4. Lolipop78709

    Lolipop78709 Creeper

    Messages:
    5
    :)

    $items = $player->getInventory()->getContents();
    foreach($items as $key => $item){
    $form->addDropdown("Select an item below that youd like to repair.", [$item->getName()]);
    }
     
  5. dbcooper

    dbcooper Spider Jockey

    Messages:
    32
    GitHub:
    dbcooper
    Could you send the full code?
     
  6. Lolipop78709

    Lolipop78709 Creeper

    Messages:
    5
    #use pocketmine\item\{ItemFactory, Item};

    public function repairForm($player){
    $formapi = $this->plugin->getServer()->getPluginManager()->getPlugin("FormAPI");
    $form = $formapi->createCustomForm(function(Player $player, $data = null){

    $options = $data[1];

    if($options != null){
    switch($options){

    case 1:
    $player->sendMessage("testing...");
    break;
    }
    }

    $form->setTitle("§c--= §l§dBlacksmith§r§c =--");
    $form->addLabel("Select an item below for repairing.");

    $items = $player->getInventory()->getContents();
    foreach($items as $key => $item){
    $form->addDropdown("Select an item below that youd like to repair.", [$item->getName()]);
    }

    $form->sendToPlayer($player);
    }
    }
     
  7. dbcooper

    dbcooper Spider Jockey

    Messages:
    32
    GitHub:
    dbcooper
    That does not work at all ;-;. I tried again with the method you gave and the only problem was that it was opening a form for every item in the player’s inventory...
     
  8. dbcooper

    dbcooper Spider Jockey

    Messages:
    32
    GitHub:
    dbcooper
    PHP:
    public function repairForm($player){
        
    $options = [];
        
    $items $player->getInventory()->getContents();
    foreach(
    $items as $key => $item){
    if(
    $item instanceof Durable){
        }
        
    $form $this->plugin->createCustomForm(function (Player $player, array $data) use ($item) {
        if(isset(
    $data[1])){
                  
    $slot $options[array_keys($options)[$data[1]]];
                  }
        });
        
    $form->setTitle("§c--= §l§dBlacksmith§r§c =--");
        
    $form->addLabel("Select an item below for repairing.");
    $form->addDropdown("Select an item below that youd like to repair.", [$item->getName()]);
        
    $form->sendToPlayer($player);
    }
    }
    }
     
  9. Lolipop78709

    Lolipop78709 Creeper

    Messages:
    5
     
  10. dbcooper

    dbcooper Spider Jockey

    Messages:
    32
    GitHub:
    dbcooper
    As I said above. That doesn’t work so referring to it again isn’t going to do much for me.
     
  11. dbcooper

    dbcooper Spider Jockey

    Messages:
    32
    GitHub:
    dbcooper
    If anyone else knows how to achieve this please reply ;-;
     
  12. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    PHP:
        public function repairForm(Player $player){
            
    $options = [];
            
    $optionsReference = [];
            foreach (
    $player->getInventory()->getContents() as $key => $content){
                if(
    $content instanceof Durable){
                    
    $options[] = $content->getName();
                    
    $optionsReference[$key] = $content->getName();
                }
            }
            
    $form $this->plugin->createCustomForm(function (Player $player, array $data) use ($optionsReference) {
                if(isset(
    $data[1])){
                    
    $slot array_keys($optionsReference)[$data[1]];
                }
            });
            
    $form->setTitle("§c--= §l§dBlacksmith§r§c =--");
            
    $form->addLabel("Select an item below for repairing.");
            
    $form->addDropdown("Select an item below that you'd like to repair."$options);
            
    $form->sendToPlayer($player);
        }
    Arrays with associative keys count as objects :/
     
    Last edited: Oct 6, 2018
    dbcooper likes this.
  13. dbcooper

    dbcooper Spider Jockey

    Messages:
    32
    GitHub:
    dbcooper
    Thanks for the proper response.
     
  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.