PlayerInteractEvent

Discussion in 'Development' started by SavionLegendZzz, Jan 9, 2019.

  1. SavionLegendZzz

    SavionLegendZzz Spider Jockey

    Messages:
    48
    GitHub:
    savionlegends
    Okay so i am making a lil minigames plugin that involves "guns" and i want to make it where if the player hold the screen the "gun" shpuld shoot rapidly. Here is my code
    PHP:
    /**
         * @param PlayerInteractEvent $event
         */
        
    public function onInteract(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
            
    $inventory $player->getInventory();
            
    $class $this->getUtils()->getClassManager($player);
            if(
    $class instanceof ClassManager){
                if(
    $event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_AIR){
                    return;
                }
                if(
    $class->getPrimary() !== null && $inventory->getItemInHand()->getId() === $class->getPrimary()->getGunItem()->getId()){
                    
    $class->getPrimary()->shoot();
                }else if(
    $class->getSecondary() !== null && $inventory->getItemInHand()->getId() === $class->getSecondary()->getGunItem()->getId()){
                    
    $class->getSecondary()->shoot();
                }
            }
        }
    but it does not shoot rapidly it only shoots once per press/touch; or repress so what is the problem?
     
  2. Diduhless

    Diduhless Witch

    Messages:
    56
    GitHub:
    Diduhless
    There's no way to check if a player is holding tap in the air.
    I'd call a task in the event that would have the initial item stored in it, to then shoot a bullet on each tick if the the player's hand item is the one that you stored.
     
    SavionLegendZzz likes this.
  3. wolfdale

    wolfdale Baby Zombie

    Messages:
    166
    You might want to use a stack of snowballs as the item, just make sure to cancel the event
     
  4. Muqsit

    Muqsit Wither Skeleton Verified

    Messages:
    1,441
    GitHub:
    muqsit
    The problem with items like snowballs is that you'll be limiting the fire rate of the gun. Snowballs can be shot like once per 8 ticks.
     
  5. wolfdale

    wolfdale Baby Zombie

    Messages:
    166
    At least its an legitimate way to detect that the player is holding down the screen, i cant think of any other way :p
     
  6. SavionLegendZzz

    SavionLegendZzz Spider Jockey

    Messages:
    48
    GitHub:
    savionlegends
    I use snowballs as the "bullets"
     
  7. wolfdale

    wolfdale Baby Zombie

    Messages:
    166
    It doesn't matter as long as you cancel the event
     

Share This Page

  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.