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

Entity follows player

Discussion in 'Development' started by #A6543, Jan 19, 2017.

  1. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    $entity->setNameTag("Hello")
     
  2. #A6543

    #A6543 Zombie

    Messages:
    267
    Oh ok. Thanks.

    And is there a way to block entity spawning using spawneggs?
     
  3. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Just cancel PlayerInteractEvent if item id is 383
     
  4. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    It is automatic closed in server software
     
  5. #A6543

    #A6543 Zombie

    Messages:
    267
    The movement is not working! And setNameTag does nothing
     
  6. #A6543

    #A6543 Zombie

    Messages:
    267
    How can I set the visible? And do u know how to make the entity follow $player?
     
  7. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
  8. #A6543

    #A6543 Zombie

    Messages:
    267
    They use packets in this plugin

    I tried this to move the entity:
    PHP:
    public function onPlayerMove(PlayerMoveEvent $event) {

    $player $event->getPlayer();


    $entity $player->getLevel()->getEntity($this->id);

    $speed 1;
    $x $player->x;
    $y $player->y;
    $z $player->z;
    if(
    $x ** $z ** 0.7){
    $motionX 0;
    $motionZ 0;
    }else{
    $diff abs($x) + abs($z);
    $motionX $speed 0.15 * ($x $diff);
    $motionZ $speed 0.15 * ($z $diff);
    }
    $entity->move($motionX$y$motionZ);
     
  9. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Is the entity a real entity or a fake one sent to the client? btw you need to call $entity->updateMovement() to send the movement
     
  10. #A6543

    #A6543 Zombie

    Messages:
    267
    Now I get this error:
    Code:
    Call to protected method pocketmine\entity\Entity::updateMovement()
    *And the entity is not visible (only If I use the move stuff)
     
  11. #A6543

    #A6543 Zombie

    Messages:
    267
    Is there another way to move Entitys?
     
  12. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Oh my bad :p use $entity->level->addEntityMotion() instead, if you want to add yaw and pitch use $entity->level->addEntityMovement()
     
  13. #A6543

    #A6543 Zombie

    Messages:
    267
    Code:
    Argument 1 passed to pocketmine\level\Level::addEntityMotion() must be of the type integer,
     
  14. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Look at the function Level::addEntityMotion() to get correct arguments ;)
     
  15. #A6543

    #A6543 Zombie

    Messages:
    267
    I found something. But I get only errors.
    PHP:
    $entity->level->addEntityMotion($id$motionX$y$motionZ);
    Code:
    Argument 5 passed to pocketmine\level\Level::addEntityMotion() must be of the type float
     
  16. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Level::addEntityMotion(int $chunkX, int $chunkZ, int $entityId, float $x, float $y, float $z)
    example:
    $entity->level->addEntityMotion($entity->chunk->getX(),$entity->chunk->getZ(),$entity->getId(),$motionX,0,$motionZ)
     
  17. #A6543

    #A6543 Zombie

    Messages:
    267
    Code:
    Call to protected method pocketmine\entity\Entity::updateMovement() from co
    ntext
     
  18. #A6543

    #A6543 Zombie

    Messages:
    267
    What is wrong with this?
     
  19. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    You shouldn't call that method anymore
     
  20. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    That means that method can only be called inside a class that extends Entity
     
  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.