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

Player damage by player

Comments in 'Plugin Development' started by mamayadesu, Feb 23, 2015.

  1. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
    What function is responsible for the player damage by other player? Also you can give examples?
  2. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Last edited: Feb 23, 2015
    iksaku likes this.
  3. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
  4. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Your own problem.
  6. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
    No. He wrote "instace", not "instaNce". You can help me?
  7. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Code:
    /*
      * @ param EntityDamageByEntityEvent $event
      *
      * @priority LOW
      * @ignoreCancelled true
      */
      public function EntityDamageByEntity(EntityDamageByEntityEvent $event){
         if($event->getDamager() instanceof Player and $event->getEntity() instanceof Player){
            //code
           //bla bla
           //bla bla bla
           //bla bla bla bla
         }
      }
    
  8. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
    Why
    PHP:
    $event->getDamager instanceof Player
    and/or
    PHP:
    $event->getEntity instanceof Player
    returns false?
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You have to register the handler as EntityDamageEvent and check if $event instanceof EntityDamageByEntityEvent
    iksaku likes this.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It means the damager/victim is not a player.
  11. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    It has to be
    PHP:
    $event->getDamager() instanceof Player
    instead of
    PHP:
    $event->getDamager instanceof Player
    You are trying to access a property that doesn't exist
    hoyinm14mc and PEMapModder like this.
  12. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Oh
  13. mamayadesu
    Offline

    mamayadesu Active Member Plugin Developer

    Joined:
    Sep 19, 2013
    Posts:
    146
    Plugins:
    4
    Minecraft User:
    mamayadesu
    It returns even if it is the player. If not to use that "if"
    PHP:
    $entity $event->getEntity();
    $damager $event->getDamager();
    if((
    $entity instanceof Player) && ($damager instanceof Player))
    It works.
  14. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Weird, you have use pocketmine/Player?
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If didn't, it should've crashed.

Share This Page

Advertisement