hey , so i have this plugin i made which sets random names to a item basically a gkit plugin but the names never set to the item , heres my code PHP: $tank = [ '§r§f§2GKit Kit §eTank I', '§r§f§2GKit Kit', '§r§f§2GKit Kit', '§r§f§2GKit Kit' ]; $tank1 = [ '§r§f§2GKit Kit §eTank I', '§r§f§2GKit Kit', '§r§f§2GKit Kit', '§r§f§2GKit Kit' ]; $random = $tank[mt_rand(0, count($tank) - 1)]; $random1 = $tank1[mt_rand(0, count($tank1) - 1)]; $helmet->setCustomName("§r§f§2GKit Kit"); $boots->setCustomName("§r§f§2GKit Kit"); $chest->setCustomName($random); $leggings->setCustomName($random1); // Adding GKit to inventory $player->getInventory()->addItem($helmet, $leggings, $chest, $boots); $player->sendMessage("§c§l TheVortex §7>> §r§f§aYou just got the Tank Kit!"); }
Yes chest helmet leggings and boots are all set to Diamond ID gear , 310 , 311 , 312 , 313 and obviously with the count and meta
I don't believe the "addItem" function works this way, so you can try this to see if it helps. PHP: $player->getInventory()->addItem($helmet, 0, 1);$player->getInventory()->addItem($chest, 0, 1);$player->getInventory()->addItem($leggings, 0, 1);$player->getInventory()->addItem($boots, 0, 1);
Your belief is not correct. See https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/inventory/BaseInventory.php#L245
Define the helmet and set it properly. PHP: $helmet = Item::get(310,0,1);$helmet->setCustomName("YourName");/** @var Player $player */$player->getInventory()->addItem($helmet);//This would Add it to their inventory, not set it automatically as their helmet.//This would$player->getInventory()->setHelmet($helmet);$player->sendArmorContents();
Am so confused how it should be can someone just be helpful? additem($helmet, $chest, $boots, $leggings); works because I receive the items but the names don't set
OP only wants to set the custom name! The code you originally had should be working as long as the items you were adding were Item objects
this is my code which doesn't set the name to the item PHP: public function gkitTank(Player $player){ $helmet = Item::get(310, 0, 1); $chest = Item::get(311, 0, 1); $leggings = Item::get(312, 0, 1); $boots = Item::get(313, 0, 1); // Adding enchantment , Protection IV $protection = Enchantment::getEnchantment(0); $protection->setLevel(4); $helmet->addEnchantment($protection); $chest->addEnchantment($protection); $leggings->addEnchantment($protection); $boots->addEnchantment($protection); // Adding Tank I $tank = [ '§r§f§2GKit Kit\n §eTank I', '§r§f§2GKit Kit', '§r§f§2GKit Kit', '§r§f§2GKit Kit', ]; $random = $tank[mt_rand(0, count($tank) - 1)]; $random1 = $tank[mt_rand(0, count($tank) - 1)]; $chest->setCustomName($random); $leggings->setCustomName($random1); // Adding GKit to inventory $player->getInventory()->addItem($helmet, $legggings, $chest, $boots); $player->sendMessage("§c§l TheVortex §7>> §r§f§aYou just got the Tank Kit!") }
I think it's because of incantations, I have this same error, I can not add custom name after adding an incantation in the item
Do you mean an enchant? PHP: public function gkitTank(Player $player){ $helmet = Item::get(310, 0, 1); $chest = Item::get(311, 0, 1); $leggings = Item::get(312, 0, 1); $boots = Item::get(313, 0, 1); // Adding Tank I $tank = [ "§r§f§2GKit Kit\n §eTank I", //possibly use " instead of ' "§r§f§2GKit Kit", "§r§f§2GKit Kit", "§r§f§2GKit Kit" ]; $random = $tank[mt_rand(0, (count($tank) - 1))]; $random1 = $tank[mt_rand(0, (count($tank) - 1))]; var_dump($chest->getName()); // pre-dump $chest->setCustomName($random); var_dump($chest->getName()); // post-dump $leggings->setCustomName($random1); // Adding enchantment , Protection IV $protection = Enchantment::getEnchantment(0); $protection->setLevel(4); $helmet->addEnchantment($protection); $chest->addEnchantment($protection); $leggings->addEnchantment($protection); $boots->addEnchantment($protection); // Adding GKit to inventory $player->getInventory()->addItem($helmet, $legggings, $chest, $boots); $player->sendMessage("§c§l TheVortex §7>> §r§f§aYou just got the Tank Kit!") }