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

Create npc

Discussion in 'Development' started by SkySeven, Apr 16, 2017.

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

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    hello,
    How to create a simple npc that does not move?
    How to detect it at EntityDamageEvent ?
    thank you in advance :)
     
  2. Ad5001

    Ad5001 Silverfish

    Messages:
    16
    GitHub:
    ad5001
    An human or an entity?
     
    SkySeven likes this.
  3. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    human :)
     
  4. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    AddPlayerPacket to create him then on DataPacketReceiveEvent check if he's hurting him :)
     
  5. Matthew

    Matthew Baby Zombie

    Messages:
    167
    GitHub:
    matthww
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    No. Don't use DataPacketReceiveEvent. If you can use a PocketMine event, use a PocketMine event. Simply use EntityDamageByEntityEvent. DataPacketReceiveEvent is very aggressive, and you should only use it if you can't do what you want to do without it.
     
    Last edited: Apr 16, 2017
    jasonwynn10, Muqsit, Zuruki and 3 others like this.
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Another alternative would be to use the search bar.
     
  8. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Yeah, it's getting called whenever a packet is received but think about how many other API and event calls you'll be saving by intercepting the packet. When you think about it logically, you'll actually be saving CPU time by handling it yourself (assuming you don't call more functions or events than PocketMine would). PocketMine performs a switch on every packet a player sends anyway so I don't see how another, earlier switch could cause your server too much harm performance wise.
     
    Muqsit and jasonwynn10 like this.
  9. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    And EntityDamageByEntityEvent doesn't detect it (i'm not sure)
     
  10. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Of course it does. If you hit it you hit an entity, and you are a player => entity which means damage by entity which means EntityDamageByEntityEvent. See Slapper as an example.
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Forum rules have been updated in the light of the rise of posts like this.
     
  12. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    PHP:
        public function onClick(\pocketmine\event\entity\EntityDamageEvent $e) {
            if(
    $e instanceof \pocketmine\event\entity\EntityDamageByEntityEvent) {
                
    $p $e->getDamager();
                
    $entity $e->getEntity();
                if(
    $entity instanceof Player && $p instanceof Player) {
                }
                if(
    $entity instanceof Human) {
                    
    $e->setCancelled();

                    if(
    $entity->getNameTag() === "yournametag") {
                        
    $this->getServer()->dispatchCommand($p"yourcommand");
                     }    
                   }
                 }
               }
    Yes you can use with EntityDamageByEntityEvent example for you .
     
    Last edited: Apr 19, 2017
  13. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    I don't need your help xd, i already find how to do this since a long time..
     
  14. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This will not detect the specific entity you created.
    I recommend storing a flag in the entity NBT that identifies that your plugin created it. You can then check it in the event handler.
     
    Marabou likes this.
  15. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Yeah true but I don't use this code ;)
     
  16. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    This is my code, and apparently @Marabou don't know how to handle it xd
    PHP:
    public function onPacketReceived(DataPacketReceiveEvent $event){
            
    $pk $event->getPacket();
            
    $player $event->getPlayer();
            if(
    $pk instanceof InteractPacket and $pk->action === InteractPacket::ACTION_LEFT_CLICK){
                if(
    $pk->target == $IdOfMyNPC){
                    
    //code to execute
                
    }
            }
        }
     
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.