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

How could i check if a player is looking to another or not ?

Discussion in 'Development' started by friscowz, Oct 21, 2017.

  1. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    I Belive that i did make that thing before but i don't remember.
     
  2. samjmckenzie

    samjmckenzie Spider

    Messages:
    7
    GitHub:
    samjmckenzie
  3. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Try Player->getTargetEntity();

    PHP:
    public function check(Player $player) {
            
    $entity $player->getTargetEntity();
            if(
    $entity instanceof Player) {
                return 
    true;
            }
            return 
    false;
        }
     
  4. alexwolf_dev

    alexwolf_dev Spider Jockey

    Messages:
    43
    GitHub:
    Frago9876543210
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    blablabla//todo: do not forget change this

    use pocketmine\event\Listener;
    use 
    pocketmine\event\server\DataPacketReceiveEvent;
    use 
    pocketmine\network\mcpe\protocol\InteractPacket;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase implements Listener{

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

       public function 
    onLooking(DataPacketReceiveEvent $e){
          
    $pk $e->getPacket();
          if(
    $pk instanceof InteractPacket){
             
    $player $this->getServer()->findEntity($pk->target);
             if(
    $player === null){
                return;
             }
             if(
    $player instanceof Player){
                
    var_dump($player->getName());
             }
          }
       }
    }
     
  5. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    there is some maths calculs to get the exact view im sure of that and @samjmckenzie you linked me Java/Bukkit codes .-.
     
  6. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    i like how you added the "//todo: do not forget change this" and also made the whole code XD, man im doing these things since 2016
     
  7. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    huh lol. Friscowz it's you! ^^
     
    friscowz likes this.
  8. samjmckenzie

    samjmckenzie Spider

    Messages:
    7
    GitHub:
    samjmckenzie
    Yes, it was Java. That's why I said you could port it.
     
  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.