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

$player->getLastDamageCause();

Comments in 'Plugin Development' started by Xenturio, Aug 10, 2015.

  1. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    $cause = $player->getLastDamageCause();

    is there a bug in dev 1257? i cant use it anymore

    PHP:
    public function onPlayerDeathEvent(PlayerDeathEvent $event)
        {
            
    $player $event->getEntity();
            if (
    $player instanceof Player)
            {
                
    $cause $player->getLastDamageCause();
              
                if(
    $cause instanceof EntityDamageByEntityEvent)
                {
                    
    $damager $cause->getDamager();
                    if(
    $damager instanceof Player)
                    {
                       
    $name $damager->getName();
                       
    $this->stats[$name]['Kills'] = ($this->stats[$name]['Kills']+1);
                    }
                }
            }  
        }
    $cause = $player->getLastDamageCause(); <--- this dont work, does anyone knows why?
    jojoe77777 likes this.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I don't know how to read your mind. Explain how it doesn't work.
    iksaku likes this.
  3. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    the player died but nothing happends by this function

    $cause = $player->getLastDamageCause();

    so the code does not continue

    if($cause instanceof EntityDamageByEntityEvent)
    {
  4. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    How did the Player die?
  5. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  6. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    i really dont know what iam doing wrong here o_O i used it befor without problems and know nothing happends...
    he stop by if($cause instanceof EntityDamageByEntityEvent)
  7. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    PHP:
        public function onPlayerDeathEvent(PlayerDeathEvent $event)
        {
            
    $player $event->getEntity();
            if(!(
    $player instanceof Player))return;
           
            
    $name $event->getEntity()->getName();
            unset (
    $this->players[$name]);
            
    $player->setGamemode(0);
           
            if(isset(
    $this->players))
            {
                
    $letztespieler count($this->players);
               
                foreach(
    $this->getServer()->getOnlinePlayers() as $player)
                {
                    
    $player->sendMessage(MT::GREEN.$name.MT::RED.' died '.MT::AQUA.'-> '.MT::RED.$letztespieler.MT::GREEN.' players alive');
                }
                foreach(
    $this->players as $p)
                {
                    
    $this->getLogger()->info("$p");
                }
            }
            
    $this->getLogger()->info("1");
            
    $cause $player->getLastDamageCause();
            if(
    $cause instanceof EntityDamageByEntityEvent)
            {
                
    $this->getLogger()->info("2");
                
    $damager $cause->getDamager();
                
    $this->getLogger()->info("$damager");
                if(
    $damager instanceof Player)
                {
                    
    $this->getLogger()->info("3");
                    
    $name $damager->getName();
                    
    $this->stats[$name]['Kills'] = ($this->stats[$name]['Kills']+1);
                    
    $kills $this->stats[$name]['Kills'];
                    
    $this->getLogger()->info("$kills");
                }
            }   
        }
    this is what i tried but he stops by 1
  8. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    Code:
    :29] [Server thread/INFO]: [SurvivalHiveHungergames] haloa
    [09:25:29] [Server thread/INFO]: [SurvivalHiveHungergames] ANTOUN
    [09:25:29] [Server thread/INFO]: [SurvivalHiveHungergames] xdcoolxd
    [09:25:29] [Server thread/INFO]: [SurvivalHiveHungergames] gg_gg
    [09:25:29] [Server thread/INFO]: [SurvivalHiveHungergames] thekingAssasin
    [09:25:29] [Server thread/INFO]: [SurvivalHiveHungergames] Johannesbaere
    [09:25:29] [Server thread/INFO]: [SurvivalHiveHungergames] BesterMan
    [09:25:29] [Server thread/INFO]: [SurvivalHiveHungergames] 1
    [09:25:29] [Server thread/INFO]: Raffa was slain by Johannesbaere
    
    this is what i get from console
    thebigsmileXD likes this.
  9. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    What should it do? What do you want to see on the message?
  10. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    i want to get kills from round... but all the time player is killed nothing happends... he stop
    by if($cause instanceof EntityDamageByEntityEvent) and dont add kills
  11. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    WTF got it

    i changed
    $cause = $player->getLastDamageCause();
    into $cause = $event->getEntity()->getLastDamageCause();

    but WHY WHY WHY?????? i do at beginning $player = $event->getEntity(); ???????????????????? :eek::eek::eek::eek:
    thebigsmileXD likes this.
  12. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    it would be awesome if anyone now what iam doing wrong there... i dont understand the problem.... :confused:
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    It is a different event. One is PlayerDeathEvent one is EntityDamageByEntityEvent.
  14. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    or
    PHP:
    ($cause === EntityDamageEvent::CAUSE_ENTITY_ATTACK /* = 1 */){

    }
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I dont think that changes anything lol. But I still know that it works.
  16. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    That function is set by the PAST or LAST damage... Not the one you're currently working with, if you want to check if the current damage is an instance of EntityDamageByEntityEvent then use:
    PHP:
    if($event intanceof EntityDamageByEntityEvent){
      
    //MOAR Code! 
    }
  17. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You made a syntax error! It's instanceof, not intanceof! :p
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    lol. That is a spelling error.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Thank you so much Mr. Obvious.
    Primus likes this.
  20. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    It may not be obvious when you have a WIP browser. :)

Share This Page

Advertisement