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

Item drop from Entity

Comments in 'Plugin Development' started by zombie_Power, Oct 7, 2015.

  1. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Greetings fellow developers and forum user,

    I am looking for a little assistance, as I am trying to develop a plugin for private use. I want the Entity (in this case, a player) to drop an item, when he dies (PlayerDeathEvent). However, I am unsure, how to actually "get the item to drop, after the player dies". I know how to define $player and how it dies.

    Regards,
    Zombie
  2. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Um.

    You want to drop special items when player dies or when entity(zombie...) dies?
  3. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    If you're talking about player, use $ev->setDrops(array(Item::get(1,0,2),Item::get(198,0,1)));

    If you are talking about entity, use EntityDeathEvent and last damage cause
  4. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Player is an entity :p
  5. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Yes, but Zombie, Villager, Snowballs, Squid... are entities too.
    zombie_Power likes this.
  6. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Can you please explain why you used... just want to make it clear for me and future Pocketmine developers.


    PHP:
    (array(Item::get(1,0,2),Item::get(198,0,1)));
    I am also clearly point at "get(1,0,2)"
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    #ReadTheDocs
    array() is creating an array.
    Item::get() is in the docs, it will return an Item instance.
    Google :: since knowing that will help.
    1 is the id, 0 is the meta and 2 is the amount.
    TryoneLegendZzz and Kvetinac97 like this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    There is no difference, except that you handle different events (EntityDeathEvent and PlayerDeathEvent).
    Kvetinac97 likes this.
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    From PlayerDeathEvent you can change items that will be dropped with function setDrops($items) - $items is an array that must contain Item Objects, so you must create array:
    PHP:
    $items = array();
    Then add the Item objects Item has function named get() that requires 3 attributes - id, meta/damage, ammount:
    PHP:
    // use pocketmine\item\Item;
    $items = array(Item::get(1012), Item::get(26406));
    Now you've made array with items you want to set when player dies, now its time to set them as drops:
    PHP:
    $event->setDrops($items);
    zombie_Power likes this.

Share This Page

Advertisement