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

RemoveArrow

Discussion in 'Plugin Help' started by Howtodoit, Aug 12, 2020.

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

    Howtodoit Spider Jockey

    Messages:
    35
    I want remove arrow plugin.
    When arrow Hit the any block , Arrow is Removed.
     
  2. hexmor

    hexmor Baby Zombie

    Messages:
    110
    GitHub:
    h3xmor
    easy . i will give you the code .

    public function onArrowHit(ProjectileHitBlockEvent $event){
    if($event->getEntity() instanceof Arrow){
    $event->getEntity()->close();
    }
    }
     
  3. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    INCORRECT CODING, dont confused people
     
  4. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    wait, i forget function name, im searching to find function name :C
     
  5. Howtodoit

    Howtodoit Spider Jockey

    Messages:
    35
  6. Howtodoit

    Howtodoit Spider Jockey

    Messages:
    35
    I can Try.
    THX
     
  7. Howtodoit

    Howtodoit Spider Jockey

    Messages:
    35
    It not work
     
  8. Howtodoit

    Howtodoit Spider Jockey

    Messages:
    35
    Thx :)
     
  9. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    i found one:
    PHP:
    /**
    * @param ProjectileHitBlockEvent $event
    */

    public function onShoot(ProjectileHitBlockEvent $event) {
        
    $arrow $event->getEntity(); //getting entity obj
        
    $grass $event->getBlockHit(); //getting hit block
        
    if ($arrow instanceof Arrow) { //check if entity obj is arrow (item)
            
    if ($grass instanceof Grass) { //check if block obj is grass (example)
                
    if (!$arrow->isFlaggedForDespawn()) { // check if there is not flagged arrow, i used here to you know there is a func with this name just this :P
                    
    $arrow->flagForDespawn(); //and remove arrow when hit to block.
                
    }
            }
        }
    }
    set prefix to SOLVED ;)
     
  10. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    yes, he dont think, and then post here :L
    pls if u dont have enough xp @hexmor dont send post, thanks :p
     
  11. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    @Howtodoit also you dont need to use $arrow->isflagedfordespawn, i used that to you see there is a func to check is entity flagged or not :)
     
  12. Primus

    Primus Zombie Pigman

    Messages:
    749
    How is this confusing?
    What function name has to do with this? You can name your method however you want as long it makes sense.
    When did Block make significant difference to OP? It was never mentioned.
     
    Diduhless likes this.
  13. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    @Howtodoit just use this code in your plugin and its done:
    PHP:
    /**
    * @param ProjectileHitBlockEvent $event
    */

    public function onShoot(ProjectileHitBlockEvent $event) {
        
    $arrow $event->getEntity(); //getting entity obj
        
    $grass $event->getBlockHit(); //getting hit block
        
    if ($arrow instanceof Arrow) { //check if entity obj is arrow (item)
            
    if ($grass instanceof Grass) { //check if block obj is grass (example)
                
    $arrow->flagForDespawn(); //and remove arrow when hit to block.
            
    }
        }
    }
    if its done pls tell mw and setprefix to Solved.
     
  14. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    o_Oo_O:facepalm::facepalm::facepalm::facepalm:

    imean :
    PHP:
    public function flagForDespawn() : void{
       
    $this->needsDespawn true;
       
    $this->scheduleUpdate();
    }
    dont REPALY for mockey things.
     
  15. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    because thats not working for people (idk why) also i tried to do that with $arrow->close but didnt removed / killed arrow entity, but i used my own code and working.
     
    Primus likes this.
  16. Primus

    Primus Zombie Pigman

    Messages:
    749
    upload_2020-8-12_17-48-25.png
    This might do the job for you
    PHP:
    <?php

    /**
     * @name NoArrow
     * @main Primus\NoArrow
     * @version 1.0.0
     * @api 3.0.0
     */

    namespace Primus {

        class 
    NoArrow extends \pocketmine\plugin\PluginBase implements \pocketmine\event\Listener {

            public function 
    onEnable() {
                
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }

            public function 
    removeArrowOnBlockCollision(\pocketmine\event\entity\ProjectileHitBlockEvent $e) {
                if(
    $e->getEntity() instanceof \pocketmine\entity\projectile\Arrow) {
                    
    $e->getEntity()->flagForDespawn();
                }
            }

        }

    }
    Save the code inside plugins folder as NoArrow.php, it should work fine.

    You're right. It doesn't work as I would think it should.
     
  17. Howtodoit

    Howtodoit Spider Jockey

    Messages:
    35
    I can to do this
    PHP:
    public function onShoot(ProjectileHitBlockEvent $event) {
        
    $arrow $event->getEntity(); //getting entity obj
        
    $air $event->getBlockHit(); //getting hit block
        
    if ($arrow instanceof Arrow) { //check if entity obj is arrow (item)
            
    if (!($air instanceof AIR)) { //check if block obj is grass (example)
                
    $arrow->flagForDespawn(); //and remove arrow when hit to block.
            
    }
        }
    }
     
  18. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    this code is what did i say to him?!! why you send mocky posts to add more msg numbers to be notable? XD
     
  19. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    set prefix to Solved pls ;)
     
  20. Howtodoit

    Howtodoit Spider Jockey

    Messages:
    35
    I got Error
    Code:
    [22:25:14] [Server thread/CRITICAL]: ReflectionException: "Class pocketmine\event\entity\ProjectileHitBlockEvent does not exist" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 766
    
     
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.