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($sender, int $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($dataid, false)) . $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($dataid, false)) . $this->getNameByData($dataid) . " §7enchantment."]); $item2 = Item::get(340, 0, $amount); $sender->getInventory()->addItem($item2); $sender->addXp(-$this->getCost($dataid) * $amount); } }); $form->setTitle($ce->getRarityColor((int)$this->getNameByData($dataid, false)) . $this->getNameByData($dataid)); $form->addLabel("Cost: " . $this->getCost($dataid) . " EXP"); $form->addSlider("§7Amount",1,64); $form->sendToPlayer($sender); }
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];
Same error on this line: (I changed the file if you're wondering why it's in a different folder) PHP: $item2 = Item::get(340, 0, $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"