What is wrong?

Discussion in 'Development' started by #A6543, Feb 21, 2017.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    PHP:
    $pk = new LoginPacket();
    echo 
    "Info: ".$pk->username;
     
  2. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    What is the problem? What error or outcome does this give you? We need some info about the problem.
     
    applqpak and Muqsit like this.
  3. #A6543

    #A6543 Zombie

    Messages:
    267
    If I write no error, then there is no error... It only writes Info:
     
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You're sending an empty Login packet and expect it to work? Hm?
    If you're creating a packet you'll have to do $pk->username = $username;...
     
    applqpak likes this.
  5. #A6543

    #A6543 Zombie

    Messages:
    267
    But I want to get something from the Packet. Not sending it to the player...
     
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Then use DataPacketReceiveEvent...

    You're creating a new packet right now.
     
    applqpak likes this.
  7. #A6543

    #A6543 Zombie

    Messages:
    267
    How can I get the name in the PlayerLogin packet?? I don't want to use other packets. I need to get it from PlayerLogin
     
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    and use print_r/var_dump
    afaik you can do things like $packet->usrnm = $rank." ".$packet->usrnm as a very bad example
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    DataPacketReceiveEvent:
    if $pk instance of TargatedPacket
    dump $pk
     
    Sandertv likes this.
  10. #A6543

    #A6543 Zombie

    Messages:
    267
    Ou. And how can I get the username using that?
     
  11. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    $pk->username?
    PHP:
            public function onDataPacket(\pocketmine\event\server\DataPacketReceiveEvent $ev){
                
    $packet $ev->getPacket();
                if(
    $packet instanceof \pocketmine\network\protcol\LoginPacket){
                    
    $username $packet->username;
                }
            }
     
    applqpak likes this.
  12. #A6543

    #A6543 Zombie

    Messages:
    267
    And how can I run it in PlayerJoinEvent? $this->onDataPacket(); doesn't work
     
  13. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    :facepalm:
    Just freaking tell us that you want to get the username on PlayerJoinEvent
    /** @var $ev PlayerJoinEvent */
    $name = $event->getPlayer()->getName();
     
    Last edited: Feb 21, 2017
    applqpak likes this.
  14. #A6543

    #A6543 Zombie

    Messages:
    267
    Nooooo..... The name was only an example wtf.
     
  15. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    of course, you need to wait for a player to join to trigger it
     
    applqpak likes this.
  16. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    Than what do you want?
     
    applqpak likes this.
  17. #A6543

    #A6543 Zombie

    Messages:
    267
    ... There is an error... Undefined method
     
  18. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    where? using what code? exact error? give us info please.
     
    applqpak and EdwardHamHam like this.
  19. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    We can't really help you if we don't know all the details. We're not robots.
     
    applqpak likes this.
  20. #A6543

    #A6543 Zombie

    Messages:
    267
    Error:
    Code:
    Argument 1 passed to Plugin\Main::onDataPacket() must be an instance of pocketmine\event\server\
    DataPacketReceiveEvent, instance of pocketmine\Player
    
    Code:
    PHP:
    public function onDataPacket(\pocketmine\event\server\DataPacketReceiveEvent $ev){
                
    $packet $ev->getPacket();
                if(
    $packet instanceof \pocketmine\network\protcol\LoginPacket){
                    
    $username $packet->username;
    echo 
    "-> ".$username;
                }
            }
    public function 
    onPPreLogin(PlayerPreLoginEvent $event)
     {
     
    $player $event->getPlayer();
    $name $player->getName();
    $this->onDataPacket($player);
     

Share This Page

  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.