1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

ENTIY MOVE AND HIT PLAYER

Discussion in 'Plugin Help' started by WoolChannel3295, May 16, 2021.

  1. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    hey, i need help. How to make a zombie and when the player gets close, the zombie moves and hits the player by code ?
     
  2. ComorDev

    ComorDev Spider

    Messages:
    11
    GitHub:
    comordev
    PHP:
    if ($zombie->distance($player) < 1) {
                        
    $packet = new AnimatePacket();
                        
    $packet->action AnimatePacket::ACTION_SWING_ARM;
                        
    $packet->entityRuntimeId $zombie->getId();
                        
    $player->dataPacket($packet);
                        
    $player->setHealth($player->getHealth() - 1);
                    }
     
    WoolChannel3295 likes this.
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Instead of setting the player's health, a better way could be actually making the zombie entity attack the player by calling entity damage event.

    PHP:
    $zombie->attack(new EntityDamageEvent($zombieEntityDamageEvent::CAUSE_CUSTOM$damageValue));
    This will cause the player to take knockback, which I think is better.
     
    WoolChannel3295 likes this.
  4. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    Thanks very much!! :)
     
  5. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    No problem!
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.