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

Check Player death cause in PlayerDeathEvent

Comments in 'Plugin Development' started by deot, Nov 12, 2015.

  1. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Hi,
    How can i check if player death cause is void??
    Now, i'm using this and it's not working
    PHP:
    if($e->getEntity()->getLastDamageCause() == 11){
        
    //CODE
    }
    Of course, it give me this error:
    Code:
    12.11 18:34:37 [Server] Server thread/NOTICE ClassCastException: "Object of class pocketmine\event\entity\EntityDamageEvent could not be converted to int" (E_NOTICE) in "/MinedoxCore-Smash_v1.0.0.phar/src/MDCore/MDCore" at line 303
    12.11 18:34:37 [Server] Server thread/CRITICAL "Could not pass event 'pocketmine\event\player\PlayerDeathEvent' to 'MinedoxCore-Smash v1.0.0': Object of class pocketmine\event\entity\EntityDamageEvent could not be converted to int on MDCore\MDCore
    i cant use that "11" or "EntityDamageEvent::CAUSE_VOID" at there... So, anyway to check it? Pls help :)
    Legoboy0215 likes this.
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Entity->getLastDamageCause() returns EntityDamageEvent or null, not an integer. Please look at the source code next time before creating a thread: https://github.com/PocketMine/Pocke...3589b64/src/pocketmine/entity/Entity.php#L647 So it should be $e->getEntity()->getLastDamageCause()->getCause(), which will return an integer. Leave a like if this helped! :)
  3. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    *cough* solved tag?
  4. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event){
    $player $event->getPlayer();
       
    $cid $player->getLastDamageCause()->getCause();
       switch(
    $cid){
         case 
    EntityDamageEvent::CAUSE_VOID:
           
    /*code*/
           
    break;
    /*keep going on*/
    Lol, just did something like this for someone else :p
  5. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    LOL :p Im more interested in /*code*/ and /*keep going on*/ xD :p hahaha
  6. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    What do you exactly want to achieve?

Share This Page

Advertisement