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

Set health for mob on spawn

Discussion in 'Development' started by Nora1903, Jul 14, 2018.

  1. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    I'm using pureEntitiesX but how to set health for any mob on EntitySpawnEvent?
    I have this code but it not working:
    PHP:
        public function onEntitySpawn(EntitySpawnEvent $e) {
            
    $mobs $e->getEntity();
            if(
    $mobs instanceof \revivalpmmp\pureentities\entity\monster\Monster){
                if(
    $mobs->getName() == "Zombie"){
                    foreach(
    $this->main->getServer()->getOnlinePlayers() as $p) {
                        
    $name $mobs->getName();
                        
    $level $this->main->getLevel($p);
                        if(
    $mobs->distance($p) <= 50) {
                            
    $mobs->setNameTag(TF::GRAY."[".$level."] ".$name);
                            
    $mobs->setMaxHealth(20+1.5*$level);
                            
    $mobs->setHealth($mobs->getMaxHealth());
                            
    $mobs->setNameTagVisible(true);
                            
    $mobs->setNameTagAlwaysVisible(true);
                        }
                    }
                }
     
  2. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Are you sure PureEntitiesX trigers this event when a monster entity spawns?
     
  3. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PureEntitiesX does not allow you to change the max health of entities simply because the getMaxHealth() function overrides the Entity::getMaxHealth() function and returns the amount of health (eg: return 20) instead of using the entity's attribute map for customizing the max health.
     
  4. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    So what i need to do to change mob health on spawn? Thanks
     
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Edit the code of PureEntitiesX. Replace the return value of getMaxHealth() with $this->maxHealth or make a your own plugin where you extend the Monster class of PureEntitiesX, you register the entity and you do what I said above.
     
  6. Aviv

    Aviv Baby Zombie

    Messages:
    156
    Dont use pureentitiesx
     
    Nora1903 likes this.
  7. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    i mean where the function in PureEntitiesX that give health for mob when it spawn ?
     
  8. Aviv

    Aviv Baby Zombie

    Messages:
    156
    It is located in the file of entity itself (like Zombie.php or Pigmen.php) there should be a function called getMaxHealth() (if i remember correctly) just edit the entities that you use its not necessary to edit them all
     
  9. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Am I muted here?
     
  10. Nora1903

    Nora1903 Slime

    Messages:
    82
    GitHub:
    cuongvnz
    Sorry i didn't see xD
     
  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.