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

How to send bossbar these days

Discussion in 'Development' started by Levi, Jun 18, 2018.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    I tried BossBarApi by xenial dan but it dont seem to work for me. How can i send bossbara using pocketmine only not some api
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Not in pmmp yet
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Does this work?
    PHP:
    /** @var Player $player */
    /** @var Entity $boss */

    $pk = new BossEventPacket();
    $pk->bossEid $boss->getId();
    $pk->playerEid $player->getId();
    $pk->eventType BossEventPacket::TYPE_SHOW;
    $pk->healthPercent 100;
    $pk->unknownShort 1;
    $pk->color 1;
    $pk->overlay 1;
    $pk->title "Title";//this will probably get overridden by $boss->getNameTag()

    $player->dataPacket($pk);
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    doesn't send bossbars
     
  5. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    PHP:
    $pk = new BossEventPacket();
            
    $pk->bossEid Entity::$entityCount++;
            
    $pk->playerEid $sender->getId();
            
    $pk->eventType BossEventPacket::TYPE_SHOW;
            
    $pk->healthPercent 100;
            
    $pk->unknownShort 1;
            
    $pk->color 1;
            
    $pk->overlay 1;
            
    $pk->title "Title";//this will probably get overridden by $boss->getNameTag()
            
    $sender->dataPacket($pk);
     
    iCirgio likes this.
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    :facepalm: bossEid....
     
    xXNiceAssassinlo YT likes this.
  7. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Change your
    PHP:
     $pk>bossEid 
    to
    PHP:
    $pk->bossEid $boss->getId();
     
  8. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    what's $boss?
     
    Draglor56 likes this.
  9. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Boss is Entity
     
  10. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    What
     
  11. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    $boss is pocketmine\entity\Enitty;

    ‍♂️
     
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Any valid entity that is visible to the player, try setting it to the player's id too (same as playerEid).
     
    xXNiceAssassinlo YT likes this.
  13. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    $sender->getId() gives me player's name and rank and the title i set don't send
     
  14. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    PHP:
    $pk = new BossEventPacket();
            
    $pk->title "Title";//this will probably get overridden by $boss->getNameTag()
            
    $pk->bossEid $sender->getId();
            
    $pk->playerEid $sender->getId();
            
    $pk->eventType BossEventPacket::TYPE_SHOW;
            
    $pk->healthPercent 50;
            
    $pk->unknownShort 1;
            
    $pk->color 1;
            
    $pk->overlay 1;
            
    $sender->dataPacket($pk);
     
  15. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    On bossEid
    :facepalm: Change
    PHP:
     $sender->getId(); 
    to
    PHP:
    $boss->getId();
    $boss Entity

    Entity import =
    PHP:
    use pocketmine\entity\Entity;
     
  16. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yeah, then it works.
     
  17. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Which Entity? Be more specific with entity wtf you've commented that ten times
     
  18. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Create any useless entity and spawn it to the player. Then set the entity's entity->getId() as the bossEid. The boss bar will read out the useless entity's nametag. So if you want to change the boss bar text, you'll need to change the useless entity's nametag.

    Alternatively, you can use packets. That will put less load on your hands.
    Fill out an AddEntityPacket and send it to the player before sending the boss bar packet. Store the AddEntityPacket's entityRuntimeId somewhere, map it to the player's username or something in an array so you can get each player's AddEntityPacket's entityRuntimeId.
    PHP:
    $pk = new AddEntityPacket();//fill out the require fields.

    /** @var Player $player */
    $player->dataPacket($pk);

    //Send bossbar packet with bossEid = $pk->entityRuntimeId.

    //Now whenever you want to change the boss bar text of an entity, you need to create a SetEntityDataPacket
    $pk = new SetEntityDataPacket();
    $pk->entityRuntimeId entityRuntimeId of that AddEntityPacket;
    $pk->metadata = [
        
    Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING"Boss bar title"]
    ];
    $player->dataPacket($pk);
     
  19. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    ... I send u the import
     
  20. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    PHP:
    /** @var Zombie $z */
            
    $z Entity::ZOMBIE;
            
    $pk = new AddEntityPacket();
            
    $pk->type $z;
            
    $pk->entityRuntimeId Entity::$entityCount++;
            
    $pk->position = new Vector3();
            
    $pk->metadata[Entity::DATA_NAMETAG] = [Entity::DATA_TYPE_STRING"Title"];
            
    $sender->dataPacket($pk);
            
            
    $pbk = new BossEventPacket();
            
    $pbk->bossEid $z->getId();
            
    $pbk->eventType BossEventPacket::TYPE_SHOW;
            
    $pbk->healthPercent 1;
            
    $pbk->title "";
            
    $sender->dataPacket($pbk);
    did that and got
    Code:
    [13:49:16] [Server thread/CRITICAL]: Unhandled exception executing command 'testc' in testc: Call to a member function getId() on integer
    [13:49:16] [Server thread/CRITICAL]: Error: "Call to a member function getId() on integer" (EXCEPTION) in "test/src/gay/testc" at line 56
    
     
  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.