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

Solved What is wrong here (trying to spawn an entity)?

Discussion in 'Development' started by MalakasPlayzMCPE, Mar 30, 2018.

Thread Status:
Not open for further replies.
  1. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Code:
    PHP:
                            $player $this->getServer()->getPlayer($args[0]);
                            
    $pk = new AddEntityPacket();
                            
    $pk->entityRuntimeId Entity::$entityCount++;
                            
    $pk->type 66;
                            
    $motion = new Vector3($player->getX(), $player->getY(), $player->getZ());
                            
    $pk->motion $motion;
                            
    $pk->yaw 0;
                            
    $pk->pitch 0;
                            
    $pk->metadata = [
                                
    15 => [01],
                                
    20 => [20]
                            ];
                            
    $player->dataPacket($pk);
    Error:
    Code:
    Argument 1 passed to pocketmine\network\mcpe\NetworkBinaryStream::putVector3() must be an instance of pocketmine\math\Vector3, null given, called in phar:///custom.phar/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php on line 96 on MalakasPlayzMC\LobbyCore
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    $zombie Entity::createEntity("Zombie"$player->getLevel());
    $zombie->spawnToAll();
     
  3. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    WTF No it's a packet.
    $motion ??? wtf
    replace $motion to $pk->position

    Edited your code.
    PHP:
      $player $this->getServer()->getPlayer($args[0]);
                            
    $pk = new AddEntityPacket();
                            
    $pk->entityRuntimeId Entity::$entityCount++;
                            
    $pk->type 66;
                            
    $pk->position = new Vector3($player->getX(), $player->getY(), $player->getZ());
                            
    $pk->motion $player->getMotion();
                            
    $pk->yaw 0;
                            
    $pk->pitch 0;
                            
    $pk->metadata = [
                                
    15 => [01],
                                
    20 => [20]
                            ];
                            
    $player->dataPacket($pk);
     
  4. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    Why not use asVector3?
    PHP:
    $pk->position $player->asVector3();
     
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    What if I want to spawn the entity on player's X + 3?
     
  6. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    PHP:
    $pk->position $player->add(300);
    //", 0, 0" is actually not required, I added it for illustrative purposes
     
  7. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Wtf read the post.
     
  8. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    PHP:
      $player $this->getServer()->getPlayer($args[0]);
                            
    $pk = new AddEntityPacket();
                            
    $pk->entityRuntimeId Entity::$entityCount++;
                            
    $pk->type 66;
                            
    $pk->position = new Vector3($player->getFloorX()+3$player->getFloorY(), $player->getFloorZ());
                            
    $pk->motion $player->getMotion();
                            
    $pk->yaw 0;
                            
    $pk->pitch 0;
                            
    $pk->metadata = [
                                
    15 => [01],
                                
    20 => [20]
                            ];
                            
    $player->dataPacket($pk);
     
    MalakasPlayzMCPE likes this.
  9. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    getFloorX() or just getX()?
     
  10. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    And what exactly in the post do you mean? I don't see a problem with his suggestion.
     
  11. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Well, I used player->getX() + 3 and it is solved. Thank you @Marabou
     
  12. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    return vector of player I don't like that. the OP ask to ajust +3 in getX()
     
  13. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    That is your problem. In fact, it makes the code shorter and cleaner (if you want to use player's position, if you want x+3, then you can use add).
     
  14. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Wtf if this person has solved his post is that I fix his style of code and you can never judge his style of code he decided to code as his I decide to fix with his code? I edit with its code style and I assure you that its code style and your code style works I do not see the difference.

    It's not because PM added a vector return on Player.php that the code is not clear I assure you that here, I show you my code I am sure you will understand nothing.
     
    Last edited: Mar 31, 2018
  15. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    Oh, lol, that escalated quickly.
    1.Know the difference between style and writing code that can be and should be improved.
    2.You should not reinvent stuff, when it's possible.
    3.
    Is that supposed to prove that you write shitcode? L, m, a, o. At least you are right in something. I already don't understand a half of things you're saying.

    P.S. So sad that you removed the part about your "large PHP experience", I had so much to pick on there. But it seems that you realized it, well, good for you.
     
  16. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    You are the type of person who is hitting fast please avoid spamming this post because it has been solved. if you want to talk open an off-topic and talk about your life you're new and you already want to get noticed.

    here does not accept anyone who spam to say anything and you judge the codes of people without knowing the true personality and if I edited my post to avoid creating 'drama' as you were excited about to wait drama.
     
  17. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    To avoid "drama" you wouldn't post that "Wtf read the post". I'll recede, because you don't understand what I am saying and don't bother to make yourself understood.
     
  18. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Your explanations and your arguments do not mean anything just read I do not even understand you so much that you say sh*t.
     
  19. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    Does this mean that you want to continue this debate? Look, I suggest you to finish this. It does make sense that my words don't reach you, when you ask questions like:
     
  20. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    What is the relationship with this post ? Please do not mix anything.
    you will be banished. you sink more and more :D
     
Thread Status:
Not open for further replies.
  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.