Help with Interact(?)

Discussion in 'Development' started by Helvixer, Mar 9, 2019.

  1. Helvixer

    Helvixer Creeper

    Messages:
    4
    GitHub:
    dospoker
    How can I "track" down the end of pressing RIGHT_CLICK_AIR? Is it possible at all?

    P.s i am russian boy, my english is bad)
     
  2. KielKing

    KielKing Zombie

    Messages:
    233
    GitHub:
    kielking
    I don't really understand your question, could you please explain a bit more?
    if by "'track' down the end of pressing RIGHT_CLICK_AIR" you mean getting the block the player sees with their crosshair, you can do
    PHP:
    /** @var Player $player */
    $player->getTargetBlock();
     
  3. Helvixer

    Helvixer Creeper

    Messages:
    4
    GitHub:
    dospoker
    No, I make weapons, I want to shoot while the player presses the screen, when he stops pressing - shooting stops.
     
  4. KielKing

    KielKing Zombie

    Messages:
    233
    GitHub:
    kielking
    You could make a task, loop each player, check if they have your weapon in their hand, then check if $player->getItemUseDuration() is over 20, then shoot
     
  5. Helvixer

    Helvixer Creeper

    Messages:
    4
    GitHub:
    dospoker
    I did just that, but when I let go of the screen / RBM, the task still goes on until I click on the block or change the item.

    PHP:
    <?php

    namespace test;

    use 
    pocketmine\{
        
    Server,
        
    Player,
        
    plugin\PluginBase
    };

    use 
    pocketmine\scheduler\Task;

    //use pocketmine\math\Vector3;

    use pocketmine\{
        
    event\Listener,
        
    event\server\DataPacketReceiveEvent
    };

    //use pocketmine\event\player\PlayerInteractEvent;

    //use pocketmine\network\mcpe\protocol\PlayerActionPacket;

    class file extends PluginBase implements Listener{
      
        public function 
    onEnable(){
            
    $this->getScheduler()->scheduleRepeatingTask(new shoot($this), 2);
            
    //$this->getServer()->getPluginManager()->registerEvents($this, $this);
        
    }
      
    }

    class 
    shoot extends Task{
      
        public 
    $p;
      
        public function 
    __construct(file $pl){
            
    $this->$pl;
            
    //parent::__construct($pl, $x);
        
    }
      
        public function 
    onRun($currentTick){
            foreach(
    $this->p->getServer()->getOnlinePlayers() as $pl){
                if(
    $pl->getInventory()->getItemInHand()->getId() == 289){
                    if(
    $pl->getItemUseDuration() > 5){
                        
    $pl->sendMessage("test");
                    }
                }
            }
        }
      
    }
     
    Last edited: Mar 9, 2019
  6. KielKing

    KielKing Zombie

    Messages:
    233
    GitHub:
    kielking
    can you show your task file?

    Edit: Sorry I didn't scroll
    PHP:
    class shoot extends Task{

        public 
    $p;

        public function 
    __construct(file $pl){
            
    $this->$pl;
            
    //parent::__construct($pl, $x);
        
    }

        public function 
    onRun($currentTick){
            foreach(
    $this->p->getServer()->getOnlinePlayers() as $pl){
                if(
    $pl->getInventory()->getItemInHand()->getId() === Item::GUNPOWDER){
                    if(
    $pl->getItemUseDuration() > 20){
                        
    $pl->sendMessage("shoot");
                    }else{
                        
    $pl->sendMessage("not shoot");
                    }
                }
            }
        }

    }
    try this
     
    Last edited: Mar 9, 2019
  7. Helvixer

    Helvixer Creeper

    Messages:
    4
    GitHub:
    dospoker
    Unfortunately, there is no difference
     
  8. KielKing

    KielKing Zombie

    Messages:
    233
    GitHub:
    kielking
    what does it spew out on your console?
     

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.