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

Solved EntityDamage from another event

Comments in 'Plugin Development' started by CaptainKenji17, Feb 15, 2016.

  1. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    PHP:
    public function onMove(PlayerMoveEvent $ev){

    $p $ev->getPlayer();
    $block $ev->getPlayer()->getLevel()->getBlock($ev->getPlayer()->floor()->subtract(01));

    if(
    $ev->getTo()->getY() > $ev->getFrom()->getY() && $block->getId() == 0){

      
    $p->sendTip("TEST");

      
    $p->attack(1, new EntityDamageByEntityEvent($pEntityDamageEvent::CAUSE_CONTACT2));
    I actually wanna create a critical plugin, it's a thing that when you jump and hit player while in the air it'll register the critical. and the problem on this code EntityDamageByEntityEvent don't have getPlayer, so in this situation how do I add getEntity?
    PHP:
    $center = new Vector3($p->getX(),$p->getY(),$p->getZ());

                    
    $radius 1;

                    
    $count 3;

                    
    $particle = new CriticalParticle($center);

                    for(
    $yaw 2$y $center->y$y $center->3$yaw += (M_PI 2) / 10$y += 10){

      
    $x = -sin($yaw) + $center->x;

      
    $z cos($yaw) + $center->z;

      
    $particle->setComponents($x$y$z);

      
    $ev->getEntity()->getLevel()->addParticle($particle);

    }
    also I wanna add these particles, how?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What do you mean by "how do I add getEntity"?
    And you do not need to handle PlayerMoveEvent to know handle an attack. You only need to handle EntityDamageEvent.
    And a player is an entity.

    PHP:
    public function e_damage(EntityDamageEvent $event){
      if(!(
    $event instanceof EntityDamageByEntityEvent) or !($event->getDamager() instanceof Player)) return;
      
    $player $event->getDamager();
      
    $block $player->getLevel()->getBlock($player->subtract(01));
      if(
    $block instanceof Air){
        
    // player is attacking in air
        // spawn critical particle at $event->getEntity(), which is the victim
        
    $event->setDamage((int) ($event->getDamage() * 1.5)); // magnify the damage
      
    }
    }
    This is based on your code. However, there are a few things you may be interested to know:
    • This will only work when the entity is attacked at the exact moment the player jumped more than 1 meter high and before falling. A player jumps slightly more than 1 meter high.
    • In Minecraft, players actually only attack with critical damage when they are falling, or more precisely, when they are in air but lower than the highest position since their last jump (e.g. if you are in creative, fly up, then fly down a bit, then start killing your pig). This means, you should try to detect player movement speed instead. Try this:
      PHP:
      if($player->speed->0)
    Last edited: Feb 15, 2016
  3. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    Finally the reply I wanted has come thank you so much :D actually on my code for EntityDamageEvent if I didnt make it EntityDamageByEntityEvent it just damage player everytime the player jumps so i tried EntityDamageByEntityEvent and it didnt work because the $p = $ev->getPlayer must be getEntity, and i cant make it getEntity because the $ev is playerMoveEvent
  4. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    The first code didnt worked* and i tried the code with vector and

    [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\entity\EntityDamageByEntityEvent' to 'ServerCore v1.0': Undefined property: pocketmine\Player::$vector on ServerCore\Main
    Last edited: Feb 15, 2016
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Sorry, it should have been Player->speed not Player->vector
    CaptainKenji17 likes this.
  6. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    DAMN IT WORKS! WOW THANK U SO MUCH!!!!!!!!!!!!!!!!!!!!!!
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    May I ask what is speed->y and what does it do?
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $player->speed is a Vector3 that represents the current speed's vector of the player.

Share This Page

Advertisement