# Item drop from Entity

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

1. Offline

### zombie_PowerActive Member

Joined:
Sep 7, 2015
Posts:
239
Minecraft User:
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. Offline ### Kvetinac97Active MemberPlugin Developer Joined: Nov 17, 2014 Posts: 276 Plugins: 1 Minecraft User: Um. You want to drop special items when player dies or when entity(zombie...) dies? 3. Offline ### Kvetinac97Active MemberPlugin Developer Joined: Nov 17, 2014 Posts: 276 Plugins: 1 Minecraft User: 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. Offline

### zombie_PowerActive Member

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

### Kvetinac97Active MemberPlugin Developer

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

### zombie_PowerActive Member

Joined:
Sep 7, 2015
Posts:
239
Minecraft User:
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. Offline

### Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,724
Minecraft User:
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. Offline

### PEMapModderNotable MemberPlugin Developer

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

### PrimusNotable Member

Joined:
Apr 7, 2015
Posts:
1,470
Minecraft User:
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(1, 0, 12), Item::get(264, 0, 6)); 
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.