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

Why Zombie Not get Damage (bad eng)

Discussion in 'Help' started by Sesamo, Jul 8, 2020.

  1. Sesamo

    Sesamo Silverfish

    Messages:
    18
    GitHub:
    Lowzer
    PHP:
    function onDamage (EntityDamageEvent $event)
        {
            if (
    $event instanceof EntityDamageByEntityEvent) {
                
    $entity $event->getEntity();
                
    $damager $event->getDamager();
                
    $event->setKnockBack(0.25);
                if (
    $entity instanceof Player or $entity instanceof Zombie){
                  if(
    $damager instanceof Player) {
                    
    $item $damager->getInventory()->getItemInHand();
                    if (
    $item->getId() === 268) {
                        if (
    $this->launch[$damager->getName()][268]) {
                            
    Server::getInstance()->getScheduler()->scheduleDelayedTask(new Callback([$this,"isBreak"],[$damager,$item]),1);
                        }else{
                            
    $event->setDamage($this->getFinalDamage($entity,4));
                        }
                    }
                }
            }
        }
        }

       function 
    getFinalDamage($A,$D)
     {
      
    $S = [Item::LEATHER_CAP=>4,Item::LEATHER_TUNIC=>4,Item::LEATHER_PANTS=>0,Item::LEATHER_BOOTS=>0,Item::CHAIN_HELMET=>5,Item::CHAIN_CHESTPLATE=>6,Item::CHAIN_LEGGINGS=>0,Item::CHAIN_BOOTS=>0,Item::GOLD_HELMET=>6,Item::GOLD_CHESTPLATE=>7,Item::GOLD_LEGGINGS=>0,Item::GOLD_BOOTS=>0,Item::IRON_HELMET=>7,Item::IRON_CHESTPLATE=>8,Item::IRON_LEGGINGS=>0,Item::IRON_BOOTS=>0,Item::DIAMOND_HELMET=>10,Item::DIAMOND_CHESTPLATE=>10,Item::DIAMOND_LEGGINGS=>0,Item::DIAMOND_BOOTS=>0];
      
    $T 0;
      foreach(
    $A->getInventory()->getArmorContents() as $g => $K){
       if(isset(
    $S[$K->getId()])){
        
    $T+=$S[$K->getId()];
       }
      }
      
    $D+=-floor($D*$T*0.04);
      if (
    $D<1$D=1;
      return
    $D;
     }
    }

     
    Last edited: Jul 8, 2020
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    I suppose that this is not your code, if it is, then you should know how debugging and echoing/dumping some info in console could help you better than us.

    As for the problem, It must be in the getFinalDamage method. The armor and item inventory is now separated, perhaps you're not getting the armor contents correctly. Not sure tho, haven't used new api. Silly to ask, but is there any errors you're getting?
     
  3. Sesamo

    Sesamo Silverfish

    Messages:
    18
    GitHub:
    Lowzer
    Updated
    PHP:
    function move ($player,$eid,$damage,$type,$value true)
        {
            
            if (!isset(
    $this->pos[$eid])) return false;
            
    $H $this->pos[$eid];
            
    $F $this->motion[$eid];
            if (
    $value$F->y-=0.00;
            
    $this->pos[$eid] = new Vector3($H->x+$F->x$H->y+$F->y$H->z+$F->z);
            
    $player->level->addParticle(new FlameParticle($H,204,0,0));
            for (
    $K 1$K 4$K++) {
                
    $H = new Vector3($H->x+$F->x/$K$H->y+$F->y/$K$H->z+$F->z/$K);
                if (
    $player->level->getBlock($H)->isSolid()) {
                    
    $this->close($eid);
                    break;
                    return 
    false;
                }
                foreach (
    Server::getInstance()->getOnlinePlayers() as $p) {
                    
    $x $p->x;
                    
    $y $p->y;
                    
    $z $p->z;
                    
    $c = new Vector2($x$z);
                    if ((new 
    Vector2($H->x$H->z))->distance($c) <= 1.2 && $H->y-$p-><= 2.6 && $H->y-$p->0) {
                        if(
    $p->getName() != $player->getName()) {
                            
    $d $this->getFinalDamage($p$damage);
                            
    $ev = new EntityDamageByEntityEvent($player$pEntityDamageEvent::CAUSE_ENTITY_ATTACK$d);
                            
    $p->attack($d$ev);
                        }
                        return 
    $this->close($eid);
                             }
                        }
                        
                        foreach (
    Server::getEntity() as $ent) {
                    
    $x $ent->x;
                    
    $y $ent->y;
                    
    $z $ent->z;
                    
    $c = new Vector2($x$z);
                    if ((new 
    Vector2($H->x$H->z))->distance($c) <= 1.2 && $H->y-$p-><= 2.6 && $H->y-$p->0) {
                        if(
    $ent instanceof Zombie){
                            
    $ents $this->getFinalDamage($ent$damage);
                            
    $evt = new EntityDamageByEntityEvent($player$entEntityDamageEvent::CAUSE_ENTITY_ATTACK$ents);
                            
    $ent->attack($ents$evt);
                        }
                        return 
    $this->close($eid);
                        }
                        }
                    
                
            }
            
    Server::getInstance()->getScheduler()->scheduleDelayedTask(new Callback([$this,"move"],[$player,$eid,$damage]),1);
        }
     
  4. Sesamo

    Sesamo Silverfish

    Messages:
    18
    GitHub:
    Lowzer
    But Now Error in
    PHP:
    foreach(Server::getEntity() as $ent) {
                    
    $x $ent->x;
                    
    $y $ent->y;
                    
    $z $ent->z;
                    
    $c = new Vector2($x$z);
                    if ((new 
    Vector2($H->x$H->z))->distance($c) <= 1.2 && $H->y-$p-><= 2.6 && $H->y-$p->0) {
                        if(
    $ent instanceof Zombie){
                            
    $ents $this->getFinalDamage($ent$damage);
                            
    $evt = new EntityDamageByEntityEvent($player$entEntityDamageEvent::CAUSE_ENTITY_ATTACK$ents);
                            
    $ent->attack($ents$evt);
                        }
                        return 
    $this->close($eid);
                        }
                        }
     
  5. Sesamo

    Sesamo Silverfish

    Messages:
    18
    GitHub:
    Lowzer
    I Think it Error "Server::getEntity() as $ent"
     
  6. Sesamo

    Sesamo Silverfish

    Messages:
    18
    GitHub:
    Lowzer
    This is not my plugin But I want to make it able to damage both people and zombies too (This plugin belongs to 1.1.5. I want to play with my friends)
     
  7. Primus

    Primus Zombie Pigman

    Messages:
    749
    The code is terrifying.

    Replace Server::getEntity() to $p->getLevel()->getEntities()

    Next time gives us the error message from console.
     
  8. Sesamo

    Sesamo Silverfish

    Messages:
    18
    GitHub:
    Lowzer
  9. Sesamo

    Sesamo Silverfish

    Messages:
    18
    GitHub:
    Lowzer
    Not Work And No Error
     
  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.