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

code for giving items ?

Discussion in 'Facepalm' started by CreeperMonster, May 28, 2017.

  1. CreeperMonster

    CreeperMonster Slime

    Messages:
    81
    GitHub:
    CreeperMonster
    Anyone know how to give items to players when they spawn on some location ? or maybe other world ?
     
  2. moska

    moska Baby Zombie

    Messages:
    105
    GitHub:
    supermaxalex
    PHP:
    if($player->== /*X position there */ and $player->== /*Y position there*/ and $player->== /*Z position there*/){
    /*
     * When the player is walking
     * on this position you have
     * set for X Y Z, it will give
     * to him/her the item you
     * set down of there
     */
    $player-getInventory()->addItem(Item::get(/*ID of the block or item*//*BONUS: You can set the damage of the item/block there*/);
    }
    It's messy code, yep.
    But I need to know if you want something on a specific terrain in a world to do a better code.
     
    [deleted] likes this.
  3. CreeperMonster

    CreeperMonster Slime

    Messages:
    81
    GitHub:
    CreeperMonster
    I want to make it on my spawn
     
  4. xXSirButterXx

    xXSirButterXx Witch

    Messages:
    52
    GitHub:
    xxsirbutterxx
    PHP:
      if($player->getLevel()->getName() == "/**spawn level name**/"){ 
           
    $player->getInventory()->addItem(0Item::get(37801));
    }
    It's a little messy. But maybe try it
     
    Last edited: May 31, 2017
  5. CreeperMonster

    CreeperMonster Slime

    Messages:
    81
    GitHub:
    CreeperMonster
    Thanks Guys
     
  6. xXSirButterXx

    xXSirButterXx Witch

    Messages:
    52
    GitHub:
    xxsirbutterxx
    No problem.
     
  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.