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

add Enchant on addItem

Discussion in 'Facepalm' started by Levi, Jul 6, 2017.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Title says everything,

    I want to add enchant to this code
    PHP:
    $players->getInventory()->setChestplate(Item::get(Item::DIAMOND_CHESTPLATE));
     
  2. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    PHP:
    $players->getInventory()->setChestplate(Item::get(Item::DIAMOND_CHESTPLATE)->addEnchantment(Enchantment::getEnchantment($id)->setLevel($level)));
     
    Levi likes this.
  3. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    kazuya, dktapps and Levi like this.
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Error.

    Code:
    09:48:50 [CRITICAL] Unhandled exception executing command 'host start' in host: Argument 1 passed to pocketmine\inventory\PlayerInventory::setHelmet() must be an instance of pocketmine\item\Item, null given, called in /root/fame/plugins/VIPParticles - Copy/src/Meme/Main.php on line 51
    09:48:50 [CRITICAL] TypeError: "Argument 1 passed to pocketmine\inventory\PlayerInventory::setHelmet() must be an instance of pocketmine\item\Item, null given, called in /root/fame/plugins/VIPParticles - Copy/src/Meme/Main.php on line 51" (EXCEPTION) in "/src/pocketmine/inventory/PlayerInventory" at line 310
    
    PHP:
    $level mt_rand(1,5);
    $players->getInventory()->setHelmet(Item::get(Item::DIAMOND_HELMET)->addEnchantment(Enchantment::getEnchantment(0)->setLevel($level)));
     
  5. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    Replace $level with a number
     
  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.