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

AddPlayerPacket not working.

Discussion in 'Development' started by RumDaDuMCPE, Jul 25, 2017.

  1. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    What I am trying to do is — spawning a human NPC with an elytra wing and then extend the Elytra wing, using packets.

    Code:

    PHP:
    public function spawnTo(PlayerJoinEvent $e) {
    $player $e->getPlayer();
    $uuid $player->getUniqueId();
    $id $player->getId();
    $packet = new \pocketmine\network\mcpe\protocol\AddPlayerPacket;
    $x 100;
    $y 75;
    $z 100;
    $elytrapacket = new \pocketmine\network\mcpe\protocol\AnimatePacket;

    // Spawning Human
    $packet->uuid $uuid;
    $packet->username "";
    $packet->entityRuntimeId $id;
    $packet->eid $id;
    $packet->$x;
    $packet->$y;
    $packet->$z;
    $packet->speedX $packet->speedY $packet->speedZ 0;
    $packet->yaw 0;
    $packet->pitch 0;
    $packet->chestPlate Item::$list[444];
    //      $packet->item = getItem(Item::DIAMOND_AXE);
    //      $packet->metaData = $player->dataProperties; Doesn't work because dataProperties is protected.
    $player->dataPacket($packet);
    $player->getInventory()->sendArmorContents($player);

    // Setting Elytra to Drag.
    $elytrapacket->entityRuntimeId $id;
    $elytrapacket->animation 15// Id for 'Drag'
    $player->dataPacket($elytrapacket);
    }
    Issues that I experience:
    - Can't spawn the Entity.
    - Can't set the Item in hand.
    - Can't set dataProperties as it is a protected class (perhaps extending the class Player using my class might help.)

    Query:
    - What is the function of setting dataProperties?

    I'm afraid that I'm a bit new to the pocketmine API so any help would be greatly appreciated from my side.

    Console logged Error:

    [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'RumBenHub v1': Argument 1 passed to pocketmine\utils\BinaryStream:: putSlot() must be an instance of pocketmine\item\Item, null given, called in /MCPE/lobby/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php on line 80 on RoyalMCPE\RumBenHub\Events\RumBenHuman

    [Server thread/CRITICAL]: TypeError: "Argument 1 passed to pocketmine\utils\BinaryStream:: putSlot() must be an instance of pocketmine\item\Item, null given, called in /MCPE/lobby/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php on line 80" (EXCEPTION) in "src/pocketmine/utils/BinaryStream" at line 288
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
  3. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
  4. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    remove $packet->chestplate it dont exist too
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    $id should be an unused entity ID
    PHP:
    $id Entity::$entityCount++;
    Item in hand
    PHP:
    $packet->item Item::get(Item::DIAMOND_AXE);
    After sending the AddPlayerPacket to a player, you'll need to send MobArmorEquipmentPacket with the following values
    PHP:
    $pk = new MobArmorEquipmentPacket();
    $pk->entityRuntimeId $id;
    $pk->slots = [
        
    Item::get(Item::DIAMOND_HELMET),
        
    Item::get(Item::DIAMOND_CHESTPLATE),
        
    Item::get(Item::DIAMOND_LEGGINGS),
        
    Item::get(Item::DIAMOND_BOOTS)
    ];
     
  6. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    How do I send the MobArmorEquipmentPacket to the NPC?

    $packet->dataPacket($pk); ?? Quite sure that won't work.
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You should send packets to player(s) whom you want to show the entity to.
     
  8. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Wouldn't sending a MobArmorEquipmentPacket to a player equip the player with armor instead of the NPC? Or am I just being dumb?
     
  9. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    that's the purpose of the Entity Id. It tells the client which entity has the equipment on
     
  10. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Thanks for educating me about that. Appreciate it :D
     
  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.