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
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);
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);
Any valid entity that is visible to the player, try setting it to the player's id too (same as playerEid).
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);
On bossEid Change PHP: $sender->getId(); to PHP: $boss->getId(); $boss Entity Entity import = PHP: use pocketmine\entity\Entity;
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);
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