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

Please help me , I don't konw what happen!

Discussion in 'Plugin Help' started by Furit Cake, May 7, 2020.

  1. Furit Cake

    Furit Cake Spider

    Messages:
    11
    I try make monster plugin, And monster kill online player have error.
    How to fix it?





    TypeError: "Return value of pocketmine\entity\Entity::getNameTag() must be of the type string, null returned" (EXCEPTION) in "src/pocketmine/entity/Entity" at line 744
    18:32:55 <Server thread/Debug> #0 src/pocketmine/event/player/PlayerDeathEvent(114): pocketmine\entity\Entity->getNameTag()
    18:32:55 <Server thread/Debug> #1 src/pocketmine/event/player/PlayerDeathEvent(53): pocketmine\event\player\PlayerDeathEvent::deriveMessage(string[12] Rattlyfn2000, object pocketmine\event\entity\EntityDamageByEntityEvent)
    18:32:55 <Server thread/Debug> #2 src/pocketmine/Player(3881): pocketmine\event\player\PlayerDeathEvent->__construct(object pocketmine\Player, array[24])
    18:32:55 <Server thread/Debug> #3 src/pocketmine/entity/Living(741): pocketmine\Player->onDeath()
    18:32:55 <Server thread/Debug> #4 src/pocketmine/Player(3871): pocketmine\entity\Living->kill()
    18:32:55 <Server thread/Debug> #5 src/pocketmine/Player(1803): pocketmine\Player->kill()
    18:32:55 <Server thread/Debug> #6 src/pocketmine/level/Level(898): pocketmine\Player->onUpdate(integer 4903)
    18:32:55 <Server thread/Debug> #7 src/pocketmine/level/Level(826): pocketmine\level\Level->actuallyDoTick(integer 4903)
    18:32:55 <Server thread/Debug> #8 src/pocketmine/Server(2359): pocketmine\level\Level->doTick(integer 4903)
    18:32:55 <Server thread/Debug> #9 src/pocketmine/Server(2482): pocketmine\Server->checkTickUpdates(integer 4903, double 1588847575.02)
    18:32:55 <Server thread/Debug> #10 src/pocketmine/Server(2250): pocketmine\Server->tick()
    18:32:55 <Server thread/Debug> #11 src/pocketmine/Server(2100): pocketmine\Server->tickProcessor()
    18:32:55 <Server thread/Debug> #12 src/pocketmine/Server(1687): pocketmine\Server->start()
    18:32:55 <Server thread/Debug> #13 src/pocketmine/PocketMine(273): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[42] D:\pm............\pm............ - ......\, string[50] D:\pm............\pm............ - ......\plugins\)
    18:32:55 <Server thread/Debug> #14 src/pocketmine/PocketMine(296): pocketmine\server()
    18:32:55 <Server thread/Debug> #15 index(2): require(string[97] phar://D:/pm............/pm............ - ....../pocketmine-mp.phar/src/pocketmi)
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Your entity's getNameTag method must return a string
     
  3. Furit Cake

    Furit Cake Spider

    Messages:
    11
    And this entity's getNameTag string() same or not my monster name string()?
     
  4. Furit Cake

    Furit Cake Spider

    Messages:
    11
    Like this?
    public function getName(): string{
    return $this->getNameTag();
    }
     
  5. Furit Cake

    Furit Cake Spider

    Messages:
    11
    I try function :string is not useful :(
     
  6. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Idk how your class looks like, you'd need to send it here
     
  7. Furit Cake

    Furit Cake Spider

    Messages:
    11
    And this mine entity zombie class , if need more class I can send.
    PHP:
    <?php

    namespace pve\entity\monster\walking\WearableMonster;

    use 
    pocketmine\item\Item;
    use 
    pve\entity\monster\WearableMonster;

    class 
    AZombie extends WearableMonster{

     const 
    NETWORK_ID 32;

     public 
    $width 0.6;
     public 
    $height 1.8;
     public 
    $eyeHeight 1.62;
     
     public function 
    getName() : string{
      return 
    "Zombie";
     }
     
     public function 
    getDrops() : array{
      if(
    $this->rpg === []){
       switch(
    mt_rand(13)){
        case 
    1:
        case 
    2: return [Item::get(3670mt_rand(13))];
        default: return [];
       }
      }else{
       return [];
      }
     }

    }
     
  8. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    I think it should be getNameTag, not getName
     
  9. Furit Cake

    Furit Cake Spider

    Messages:
    11
    You mean like this?
    PHP:
    public function getNameTag() : string{
            return 
    "Zombie";
        }
     
  10. Furit Cake

    Furit Cake Spider

    Messages:
    11
    OK !Thank you pay for time answer the mine question!I fix it !And have a good time!
     
    HimbeersaftLP likes this.
  11. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    Or you can simply use the entity data value
     
    minijaham and HimbeersaftLP like 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.