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

CustomForm Input Slider Issues

Discussion in 'Development' started by NickteeChunky, Jul 24, 2019.

  1. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    I'm confused on how CustomForms work, so what I'm trying to do is have players enter a specific amount of custom enchant books to be given through a slider but I'm having issues and keeping running into this same issue. Please help me!

    Code:
    [Server thread/CRITICAL]: TypeError: "Argument 3 passed to pocketmine\item\Item::get() must be of the type integer, null given, called in C:\Users\NickteeChunky\Desktop\PocketMine-MP\Server\plugins\BookSystem\src\goldentouch74\BookSystem\Main.php on line 114" (EXCEPTION) in "src/pocketmine/item/Item" at line 104
    PHP:
        public function Confirm($senderint $dataid): void{
            
    $formapi $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $ce $this->getServer()->getPluginManager()->getPlugin("PiggyCustomEnchants");
            
    $form $formapi->createCustomForm(function ($sender$data) use($dataid$ce){
                if(
    $data !== null){
                    if(
    $sender->getCurrentTotalXp() < $this->getCost($dataid)){
                        
    $sender->sendMessage(C::RED "§cUh oh! Looks like you do not have enough XP.");
                        return;
                    }
                    
                    
    $amount $data[0];
                    
    $item Item::get(340);
                    
    $nbt $item->getNamedTag();
                    
    $nbt->setString("ceid", (string)$dataid);
                    
    $item->setCustomName($ce->getRarityColor((int)$this->getNameByData($dataidfalse)) . $this->getNameByData($dataid) . C::RESET C::YELLOW " Book");
                    
    $item->setLore([C::GRAY "§7Inspect this enchantment book to uncover a random" $ce->getRarityColor((int)$this->getNameByData($dataidfalse)) . $this->getNameByData($dataid) . " §7enchantment."]);
                    
    $item2 Item::get(3400$amount);
                    
    $sender->getInventory()->addItem($item2);
                    
    $sender->addXp(-$this->getCost($dataid) * $amount);
                }
            });

            
    $form->setTitle($ce->getRarityColor((int)$this->getNameByData($dataidfalse)) . $this->getNameByData($dataid));
            
    $form->addLabel("Cost: " $this->getCost($dataid) . " EXP");
            
    $form->addSlider("§7Amount",1,64);
            
    $form->sendToPlayer($sender);
        }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    The label is part of the form elements, the slider is your second element so you should get from index 1 instead of 0
    $amount = $data[1];
     
  3. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    Same error on this line: (I changed the file if you're wondering why it's in a different folder)

    PHP:
                    $item2 Item::get(3400$amount);
    Error:

    Code:
    [Server thread/CRITICAL]: TypeError: "Argument 3 passed to pocketmine\item\Item::get() must be of the type integer, float given, called in C:\Users\NickteeChunky\Desktop\PocketMine-MP\PocketMine-MP-master\plugins\BookSystem\src\goldentouch74\BookSystem\Main.php on line 114"
     
  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.