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

What are packets in plugin coding and how do they work?

Discussion in 'Development' started by Dolphin was the first, May 28, 2020.

  1. Dolphin was the first

    Dolphin was the first Spider

    Messages:
    13
    GitHub:
    Dalp
    What are packets in plugin coding and how do they work? Can you drop a link to some tutorial or say where i can understand packets?
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Packets are packets of information whose are sending between player and server. There are lots of packets in mcpe, you can find all implemented packets by pocketmine here. However with pocketmine api you don't need to use that classes so much because of you can replace them using simplier api methods. For example when you want send message to player, you will use

    PHP:
    Player->sendMessage($message);
    instead of

    PHP:
    $pk = new TextPacket();
    $pk->type TextPacket::TYPE_RAW;
    $pk->message $message
    Player
    ->dataPacket($pk);
    ^ In this case I show you how to send packet to player.

    Packets sent from client can be handled using DataPacketReceiveEvent, so you can check all the packets whose server handled using it.... There is also DataPacketSendEvent which is called when packet is send to player.
     
    Dolphin was the first likes this.
  3. Dolphin was the first

    Dolphin was the first Spider

    Messages:
    13
    GitHub:
    Dalp
    Thanks a lot, I seem to understand
     
  4. Dolphin was the first

    Dolphin was the first Spider

    Messages:
    13
    GitHub:
    Dalp
    My question is what does player-> dataPacket ($ pk) mean. I realized that this sends a packet to the player, but what is the “player” in the code itself, it is not a variable, but what then?
    And is it possible to write like this:
    foreach($this->getServer()->getOnlinePlayers() as $p){
    $p->dataPacket($pk);
    } ???
    And packets load the server???
    And one more question: That is, functions in the server software PocketMine-MP work with packages, and when they are executed, are packages created?
    Thank you very much again. And if you want, then do not answer the questions above.
    You already helped me, thanks
     
    Last edited: May 30, 2020
  5. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Learn php basics first, then you will understand this stuff.

    - Player is class located at \pocketmine\Player.php
    - your code should work
     
  6. Dolphin was the first

    Dolphin was the first Spider

    Messages:
    13
    GitHub:
    Dalp
    I know the basics of PHP, and even more than the basics.
     
  7. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Then you also know answer for your questions
     
  8. Dolphin was the first

    Dolphin was the first Spider

    Messages:
    13
    GitHub:
    Dalp
    well thank you
     
  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.