PHP: public function onEntityDeath(\pocketmine\event\entity\EntityDeathEvent $event){ if(($player = $event->getEntity()) instanceof \pocketmine\Player){ $event->setDrops(array_push($event->getDrops(), \pocketmine\item\Item::get($id, $meta, $count))); }}
There are a few errors in this code... EntityDeathEvent::getDrops() returns the drops array, but you cannot push a value into the array through the function array_push() returns an integer, not the drops array. If we are checking for a player's death, then why dont we use a PlayerDeathEvent? PHP: public function onPlayerDeath(\pocketmine\event\player\PlayerDeathEvent $event){ $drops = $event->getDrops(); //get the current drops array $drops[] = \pocketmine\item\Item::get(\pocketmine\item\Item::AIR, 0, 1); // Add a new Item to the array $event->setDrops($drops); // Set the new drops array}
As far as I understand, this will drop the player's inventory + the added item. How do we, for example, drop a cookie and nothing else when a player dies?