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

Solved $event->setDamage(6); off ?

Discussion in 'Help' started by Jules, Aug 13, 2018.

  1. Jules

    Jules Witch

    Messages:
    53
    GitHub:
    Julooooos
    hi how to fix it ?
    PHP:
    $event->setDamage(6);
     
  2. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    replace with $event->setModifier(6);
     
  3. Jules

    Jules Witch

    Messages:
    53
    GitHub:
    Julooooos
    thanks !
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Keep in mind that the second parameter of setModifier defines the type of modifier. Depending on the situation, you may want to use one from this list.
     
  5. Jules

    Jules Witch

    Messages:
    53
    GitHub:
    Julooooos
     
  6. Jules

    Jules Witch

    Messages:
    53
    GitHub:
    Julooooos
    i want modify an item damage.
     
  7. Jules

    Jules Witch

    Messages:
    53
    GitHub:
    Julooooos
    this is my code
    PHP:
           public function onDamage(EntityDamageEvent $event) {
                
    $damager $event->getDamager();
                
    $target $event->getEntity();
                if(
    $damager instanceof Player && $target instanceof Player){
                    
    $item $damager->getInventory()->getItemInHand();
                    if(
    $item->getId() == 352){
                        
    $event->setModifier(6);
                        
    $target->getLevel()->addParticle(new ExplodeParticle(new Vector3($target->x$target->2$target->z)));
                        
    $target->getLevel()->addParticle(new ExplodeParticle(new Vector3($target->x$target->2$target->z)));
     
    Mohamad likes this.
  8. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Oh, okay. Assuming the item extends Durable, you can use $item->applyDamage(6). If you want to change the meta value, $item->setDamage(6) would work.
     
  9. Jules

    Jules Witch

    Messages:
    53
    GitHub:
    Julooooos
    0.5 D 0.34 kB/s | TPS 20 | Load 1.5%[36m[15:40:25] [m[31m[Server thread/CRITICAL]: Could not pass event 'pocketmine\event\entity\EntityDamageByEntityEvent' to 'HyparionCore v1': Call to undefined method pocketmine\Player::applyDamage() on HyparionCore\Main[m
    [36m[15:40:25] [m[31m[Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\Player::applyDamage()" (EXCEPTION) in "HyparionCore/src/HyparionCore/Main" at line 177[m
     
  10. Jules

    Jules Witch

    Messages:
    53
    GitHub:
    Julooooos
    ca
    can you show me an example of that you say ?
     
  11. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Take the $item variable you already defined and use
    PHP:
     $item->applyDamage(6);
    Only if the item has durability, like a tool or armor. Otherwise, use
    PHP:
     $item->setDamage(6);
     
  12. Jules

    Jules Witch

    Messages:
    53
    GitHub:
    Julooooos
    PHP:
           public function onDamage(EntityDamageEvent $event) {
                
    $damager $event->getDamager();
                
    $target $event->getEntity();
                if(
    $damager instanceof Player && $target instanceof Player){
                    
    $item $damager->getInventory()->getItemInHand();
                    if(
    $item->getId() == 352){
                       
    $item->applyDamage(6);
                        
    $target->getLevel()->addParticle(new ExplodeParticle(new Vector3($target->x$target->2$target->z)));
                        
    $target->getLevel()->addParticle(new ExplodeParticle(new Vector3($target->x$target->2$target->z)));
    this is right ?
     
  13. Destroyer57

    Destroyer57 Zombie

    Messages:
    275
    Yeah.
     
  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.