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

How can I check how many entities are dying

Discussion in 'Development' started by HirschgamerYT, Aug 22, 2020.

  1. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    ofc i used this (but i saved to cfg) in my mobwars plugin (i used this to get top 3 players top zombiekillers in the end of every games)
     
  2. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    wait i'll test the code rn but i used entity zombie in Jason10w... in his EntityX plugin. (in instanceof Zombie)
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    didn’t test just saw this forum but this is how I would do it
    PHP:
    private $kills = [];

    public function 
    onDeath(EntityDeathEvent $event): void{
    $entity $event->getEntity(); //gets the entity that’s died
    $last $entity->getLastDamageCause(); //cause of death

    if($entity instanceof Zombie && $last instanceof EntityDamageByEntityEvent){ //checks if entity is zombie and if it’s attacked by entity
    $damager $last->getDamager(); //whoever attacked the entity 

    if($damager instanceof Player){ //if that damager is player
    $value 1//default value
    if(isset($this->kills[$damager->getName()])){ //checks if player name is set in kills array
    $value += $this->kills[$damager->getName()]; //adds the value from kills array to $value
    }
    if(
    $value >= 10){ //checks if value is higher or equal to 10
    unset($this->kills[$damager->getName()]); //removes player from kills array
    $damager->sendMessage("You killed 10 zombies"); //send message
    return; 
    }
    $this->kills[$damager->getName()] = $value//add the $value to array
    }
    }
    }
     
    HirschgamerYT and GodWeedZao like this.
  4. HirschgamerYT

    HirschgamerYT Spider

    Messages:
    9
  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.