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

ProjectileHitEvent

Discussion in 'Development' started by Jonas, Mar 9, 2017.

  1. Jonas

    Jonas Baby Zombie

    Messages:
    192
    How can i teleport to an arrow when i shot with a bow(ProjectileHitEvent)
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    On arrow fired by player event:
    get arrow, add nbt with the NBT named "owner" and set it to player's name

    On arrow collided event:
    check if it have a NBT named owner and check if the player is online
    remove/despawn the arrow then tp the player somewhere near the arrow that's safe to be spawned(so the player dont get stuck in weird places and die)
     
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    of which part you need a code example to understand it?

    Here is a more examples

    This one should help you with NBT
    https://forums.pmmp.io/threads/how-do-you-properly-set-nbt.1182/#post-13782

    for On arrow fired by player event
    try ProjectileLaunchEvent and check if it's fired by a player that's online

    for On arrow collided event
    try ProjectileHitEvent (not very sure) and check if it's a arrow, optionally checks if it hits on block or entity then disallowing whatever you wish
     
  4. Jonas

    Jonas Baby Zombie

    Messages:
    192
    Can you give me a complete example from that:
     
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    what you meant by complete example?
    do i need to lay out every syntax and so on?
    am i expecting too much by using too many layers of abstractions and assuming most people would be able to understand them reasonably?
    most likely i already told you what you needed to know to make it work
     
  6. Jonas

    Jonas Baby Zombie

    Messages:
    192
    Yes please the Syntax
     
  7. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    This is the plugin development subforum, not the plugin requests. If you make your own plugin, please at least try it yourself.
     
    jasonwynn10 likes this.
  8. Jonas

    Jonas Baby Zombie

    Messages:
    192
    I have it tried but it dont work and no errors comes
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    show us your code
     
  10. Jonas

    Jonas Baby Zombie

    Messages:
    192
    This is the Code
    PHP:
    public function onTeleport(ProjectileHitEvent $event) {
            
    $arrow $event->getEntity();
            if(
    $arrow instanceof Arrow) {
                
    $player $arrow->shootingEntity;
                if(
    $player instanceof Player) {
                    
    $player->teleport($arrow);
                }
            }
     
  11. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Seems ok to me, did you put this?
    PHP:
    use pocketmine\entity\Arrow;
    use 
    pocketmine\Player;
     
  12. Jonas

    Jonas Baby Zombie

    Messages:
    192
    I've forgot
    use pocketmine\Player;
     
  13. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    :facepalm:
     
  14. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    code:
    PHP:
        public function onHit(ProjectileHitEvent $ev){
            
    $arrow $ev->getEntity();
            if(
    $arrow instanceof Arrow){
                
    $x $arrow->getX();
                
    $y $arrow->getY();
                
    $z $arrow->getZ();
                
    $lvl $arrow->getLevel();
                
    $player->teleport(new Position($x$y$z$lvl));
            }
        }
     
  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.