Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Enchant function

Comments in 'Plugin Development' started by Vladt111, Sep 13, 2015.

  1. Vladt111
    Offline

    Vladt111 New Member

    Joined:
    Sep 13, 2015
    Posts:
    7
    Minecraft User:
    CMEPTb5
    What function should be used instead addEnchantment ()?

    Attached Files:

  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    PHP:
    $item->addEnchantment($enchantment);
  3. Vladt111
    Offline

    Vladt111 New Member

    Joined:
    Sep 13, 2015
    Posts:
    7
    Minecraft User:
    CMEPTb5
    PHP:
    <?php

    namespace LvL;

    use 
    pocketmine\item\Item;
    use 
    pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\item\enchantment\EnchantmentEntry;
    use 
    pocketmine\item\enchantment\EnchantmentList;

    class 
    LvL extends PluginBase {
        public function 
    onEnable(){
        
    $item Item::GOLD_SWORD;
        
    $item->addEnchantment($enchantment);
        
    $enchantment Enchantment::getEnchantment(9);
        
    $enchantment->setLevel(1000);
     }
    }
  4. Vladt111
    Offline

    Vladt111 New Member

    Joined:
    Sep 13, 2015
    Posts:
    7
    Minecraft User:
    CMEPTb5
    Where is the mistake? Why the server crash?
  5. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    $item->addEnchantment($enchantment); should be after you define $enchantment, not before... Oh and you're missing a bracket and why onEnable?...
  6. Vladt111
    Offline

    Vladt111 New Member

    Joined:
    Sep 13, 2015
    Posts:
    7
    Minecraft User:
    CMEPTb5
    Where brackets are missing and which ones?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please learn PHP. PHP executes code from front to end. That means, the first line in the function, then the second line, vice versa, is run. In your code, you attempted to use the variable $enchantment before it is defined.

    Furthermore, Item::GOLD_SWORD is an integer that stands for the item ID of a golden sword. You cannot call methods upon a variable (like $var->method()) unless the variable is an object.
    It seems like you are trying to trigger the method Item::addEnchantment(). In this case, you need to get an Item object representing a golden sword, which can be resolved through `Item::get(Item::GOLD_SWORD)`.
  8. Vladt111
    Offline

    Vladt111 New Member

    Joined:
    Sep 13, 2015
    Posts:
    7
    Minecraft User:
    CMEPTb5
    So I change the code?
  9. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Yes. Your code needs fixing.
    Last edited: Sep 17, 2015
    Hotshot_9930 likes this.
  10. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You are clearly trying to make a plugin without sufficient knowledge of PHP. Please learn some PHP, it will help.
  11. Asidert
    Offline

    Asidert Active Member Plugin Developer

    Joined:
    Oct 21, 2014
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Asidert
    Learn PHP, please...
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Learn any programming language or writing.
    Who writes a story end, beginning and start? Without the characters and setting defined, you can't write a story.
    jojoe77777 likes this.
  13. CookieSteve
    Offline

    CookieSteve Active Member

    Joined:
    Apr 22, 2014
    Posts:
    132
    Minecraft User:
    iStrqfeChris
    Everyone said Learn PHP Preety much Spam (including me)
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But that is indeed the only answer to this question. Basically, you don't understand what you are typing. I won't help you unless you know what you are trying to do and don't know what you did wrong.
    Legoboy0215 likes this.
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Change it to Learn OOP.

Share This Page

Advertisement