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

Solved Remove arrow

Discussion in 'Development' started by KHAV, Jun 21, 2018.

  1. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    How i can remove arrow when it on the ground?

    I tried
    PHP:
    if($event->getEntity()->onGround()){
    $event->getEntity()->close();
    But it doesn't work.
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    ProjectileHitBlockEvent::getEntity()->flagForDespawn();
    Avoid calling Entity->close() through plugins unless you understand what you're doing. You may end up with console errors because you're closing the entity before PocketMine has completed ticking the entity.
    Code:
    //Calling Entity->close() during an event
    class Entity {
        *PocketMine calls an Event*
        *You call Entity->close() in the event*
        *PocketMine tries to update entity's position*
        *"Failed to update entity's position because entity is closed" error spews in console*
    }
    
    //Calling Entity->flagForDespawn() during an event
    class Entity {
        *PocketMine calls an Event*
        *You call Entity->flagForDespawn() in the event*
        *PocketMine tries to update entity's position*
        *PocketMine checks if entity is flagged for despawn and despawns the entity*
    }
    
     
    JohnsonK79, KHAV and corytortoise like this.
  3. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv

    PHP:
    public function removeArrow(ProjectileHitBlockEvent $event){
    if(
    $this->inReachMoon($event->getEntity()->getOwningEntity())){
            if(
    $event->getEntity() instanceof Arrow){
                
    $event->getEntity()->flagForDespawn();
             }
            }
        }
    it doesn't work!
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    What's the inReachMoon function? Alternatively, test @Muqsit's code snippet without any extra checks, so you can be sure that it is his code that doesn't work, rather than your own. Not much help can be given without knowing that everything else can be eliminated as the cause of the problem.
     
  5. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    ReachMoon is function to check if the player in specific place, ok i will try it without anything
     
    kombanwa and corytortoise like this.
  6. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Solved..., thx Muqsit and corytortoise
     
  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.