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. HirschgamerYT

    HirschgamerYT Spider

    Messages:
    9
    How can I check how many certain entities a player kills and do something with a certain number?
     
  2. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    $count = 0;
    foreach($this->getLevelByName("StuffMap")->getEntities() as $entitys) {
    $count++;
    }
     
  3. HirschgamerYT

    HirschgamerYT Spider

    Messages:
    9
    "certain entity" like a zombie or something
     
  4. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    :|
    $count = 0;
    foreach($this->getLevelByName("StuffMap")->getEntities() as $entitys) {
    if($entities instanceof Zombie) {
    $count++;
    }
    }
     
  5. HirschgamerYT

    HirschgamerYT Spider

    Messages:
    9
    I have now counted the entities but I would like that if a player kills 10 zombies the following message comes up: You managed to kill 10 zombies
     
  6. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    :|
    use cfg, save player kills to array and save it to cfg, and foreach kill do some thing like $count++; it wi;; save players how many zombie killed but its laggy for server
     
  7. HirschgamerYT

    HirschgamerYT Spider

    Messages:
    9
  8. HirschgamerYT

    HirschgamerYT Spider

    Messages:
    9
  9. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    learn php befor creating plugins, when you dont know lessons in school, how can you take extraexam? you need to learn first, then exam.
     
  10. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    That's exactly what you should do now. Those forums are to help people with it, not to tell them to learn it on himself. Maybe you know some php basics, but to help someone you need much more knowledge. In every second post by you I see wrong information... Also try improve your English, I think google could translate your messages better than you.
     
    HirschgamerYT and Diduhless like this.
  11. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You must save each kill while EntityDeathEvent is called. Then you must find the value for player you saved.
     
    Diduhless likes this.
  12. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    ok, sorry i make my torurials better (in explation) and ok i use google translator XD to translate messages, you right
     
  13. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    use statments:
    PHP:
    use pocketmine\entity\Zombie;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    and use this:
    PHP:
    class Main extends PluginBase implements Listener
    {
        public function 
    onJoin(PlayerJoinEvent $event)
        {
            
    //save zombieKills of player to 0 if(!isset($cfg["zombieKills"])) {}
            //idk how do you want to use config, you should do this own your self
            //also register events
        
    }

        
    /**
         * @param EntityDamageByEntityEvent $event
         */
        
    public function onPvM(EntityDamageByEntityEvent $event)
        { 
    //PvM is Player vs Mob XD
            
    $damager $event->getDamager();
            
    $zombie $event->getEntity();
            
    $zombieKills 0;
            if (
    $damager instanceof Player && $zombie instanceof Zombie) {
                    if (
    $zombie->getHealth() - $event->getFinalDamage() <= 0) {
                        
    $zombieKills++;
                        
    //now you can save it to cfg, but its laggy, its better to save it with task or onDisable func..?
                        //now when player kills a zombie mob, add +1 number to his kills in cfg and you can check it if player zombieKills are === 10 sendmessage tp player, you have killed 10 zombie
                        
    $damager->sendMessage("You Killed " $zombieKills " Zombies"); //just for see plugin is working or not
                
    }
            }
        }

    }
    it should solving, sorry my last code is wring :facepalm::facepalm: its correct now :oops:
     
    Last edited: Aug 23, 2020
  14. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Why are you checking twice that Zombie is instance of zombie? Also do you know that EntityDeathEvent exists?
     
  15. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    because i wrote twice code and i forget to remove that, now edited

    i know, there isn't difference, its working, what is your problem to me?



    Why do you want to prove your superiority to others by making useless objections?
     
  16. HirschgamerYT

    HirschgamerYT Spider

    Messages:
    9
    I thank you!
     
  17. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    no problem ;)
     
  18. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    I just told how to make the code more simplier, I have not any problems with you.
     
  19. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    ok, how can we do it in your idea? idk how to, so he need to count zombie kills for each player can you send code? i want learn a more.
     
  20. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    I said it in my first post in this thread. In the next one I told you it won't work. That's all. By the way did you test the code?

    upload_2020-8-23_20-55-57.png

    ^ There are several mistakes in the code. ^
    1) The first one is that variable $zombieKills will be reseted after the function start again so player can reach max 1 zombie kill
    2) The second one is that if you would think about the code more, and didn't make mistake #1, then you would (maybe) recognise that you store values for every players in one integer public variable and that you must create array for that.
    3) If you want handle EntityDamageByEntityEvent, you must use EntityDamageEvent, and then check if it's instanceof EntityDamageByEntityEvent
    4) You already fixed that you checked that $zombie is instanceof Zombie twice ----> GOOD JOB!
     
    GodWeedZao likes this.
  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.