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

names

Discussion in 'Development' started by Teamblocket, May 5, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    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(0count($tank) - 1)];
          
    $random1 $tank1[mt_rand(0count($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!");
      }
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    can you show more? are you sure $helmet $boots $chest and $leggings are all Item objects?
     
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Incorrect and irrelevant. The AddItem function has as many parameters as is needed.
     
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Yes chest helmet leggings and boots are all set to Diamond ID gear , 310 , 311 , 312 , 313 and obviously with the count and meta
     
  5. TxnnerOS

    TxnnerOS Creeper

    Messages:
    3
    I don't believe the "addItem" function works this way, so you can try this to see if it helps.
    PHP:
    $player->getInventory()->addItem($helmet01);
    $player->getInventory()->addItem($chest01);
    $player->getInventory()->addItem($leggings01);
    $player->getInventory()->addItem($boots01);
     
    Last edited: May 5, 2017
  6. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
  7. Lowkey

    Lowkey Slime

    Messages:
    94
    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();
     
  8. Hipster

    Hipster Zombie

    Messages:
    214
    $player->getInventory()->sendContents($player);
     
  9. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    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
     
    jasonwynn10 likes this.
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    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
     
    Lowkey likes this.
  11. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    this is my code which doesn't set the name to the item
    PHP:
      public function gkitTank(Player $player){
          
    $helmet Item::get(31001);
          
    $chest Item::get(31101);
          
    $leggings Item::get(31201);
          
    $boots Item::get(31301);

          
    // 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(0count($tank) - 1)];
          
    $random1 $tank[mt_rand(0count($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!")
      }
     
  12. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    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
     
    Teamblocket likes this.
  13. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Do you mean an enchant?
    PHP:
      public function gkitTank(Player $player){
          
    $helmet Item::get(31001);
          
    $chest Item::get(31101);
          
    $leggings Item::get(31201);
          
    $boots Item::get(31301);

          
    // 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!")
      }
     
    DanielYTK likes this.
  14. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    <3 thx it worked
     
    jasonwynn10 likes this.
  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.