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

setMaxHealth on entity

Discussion in 'General discussion' started by MusicNOvas, Apr 22, 2019.

  1. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    Code:
    Call to a member function setMaxHealth() on null" (EXCEPTION) in "plugins/Boss/src/MiniBosses/Main" at line 130
    PHP:
    public function spawnBoss(string $name "Boss") {
            
    $data $this->data->get($name);
            if(!
    $data) {
                return 
    "No data, Boss does not exist";
            }elseif(!
    $this->getServer()->loadLevel($data["level"])) {
                return 
    "Failed to load Level {$data["level"]}";
            }
            
    $networkId = (int) $data["network-id"];
            
    $pos = new Position($data["x"], $data["y"], $data["z"], $this->getServer()->getLevelByName($data["level"]));
            
    $health $data["health"];
            
    $range $data["health"];
            
    $attackDamage $data["attackDamage"];
            
    $attackRate $data["attackRate"];
            
    $speed $data["speed"];
            
    $drops $data["drops"];
            
    $respawnTime $data["respawnTime"];
            
    $skin = ($networkId === 63 $data["skin"] : "");
            
    $heldItem $data["heldItem"];
            
    $scale $data["scale"] ?? 1;
            
    $nbt Boss::createBaseNBT($pos);
            
    $nbt->setTag(new ListTag("spawnPos", [new DoubleTag(""$pos->x), new DoubleTag(""$pos->y), new DoubleTag(""$pos->z)]));
            
    $nbt->setFloat("range"$range $range);
            
    $nbt->setFloat("attackDamage"$attackDamage);
            
    $nbt->setInt("networkId"$networkId);
            
    $nbt->setInt("attackRate"$attackRate);
            
    $nbt->setFloat("speed"$speed);
            
    $nbt->setString("drops"$drops);
            
    $nbt->setInt("respawnTime"$respawnTime);
            
    $nbt->setString("skin"$skin);
            
    $nbt->setString("heldItem"$heldItem);
            
    $nbt->setFloat("scale"$scale);
            
    $ent Entity::createEntity("network->id"$pos->level$nbt);
            
    $ent->setMaxHealth($health);//line 130
            
    $ent->setHealth($health);
            
    $ent->setNameTag($name);
            
    $ent->setNameTagAlwaysVisible(true);
            
    $ent->setNameTagVisible(true);
            
    $ent->spawnToAll();
            return 
    true;
        }
    The setMaxHealth() doesn't work. How can I solved this problem ?
     
  2. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    PHP:
    $ent->setHealth($ent->getMaxHealth());
     
    Last edited: Apr 23, 2019
  3. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    remove line 130 and replace line 131 with this
     
    notdrewdev likes this.
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    PHP:
    $ent Entity::createEntity("network->id"$pos->level$nbt);
    There is no such entity "network->id" thats why its null use $networkId
     
  5. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    PHP:
    $ent Entity::createEntity("/*network->id*/"$pos->level$nbt);
    It's the entity id in the folder.
     
  6. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    There is no such entity network id, use $networkId instead
     
  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.