[Info] How to detect damage applied to an NPC created with Packets.

Discussion in 'Resources' started by CaptainBern, Oct 28, 2013.

Thread Status:
Not open for further replies.
  1. Hello there, CaptainBern here.
    Today I will explain you why and how you can detect damage or interaction applied to an NPC created with packets as seen in this thread.

    Lately I have seen many people asking how to spawn NPC's and how to detect damage or interaction with them. Many people think that listening for the EntityDamageByEntityEvent will work, will this work? Short answer, -No.

    Now you may wonder why would this not work? -Well you created the npc trough packet sending so the server doesn't know about your npc, therefor interaction/damage is also undetectable by the server.

    But can I at least try? -Yes you can try, it's a waste of time tho because it won't work.

    So how do I detect interaction with my fancy npc? -This is another story. Basically, when you create an npc, you also give it an ID. Now, this happens with all entities, so whenever the player interacts with an entity he sends a Packet7UseEntity to the server. This packet contains 3 fields.
    -Field a, this is the entity-id of the player who sends the packet.
    -Field b, this is the entity-id of the entity interacted with.
    -Field c, this is the action, it's an integer/boolean, when it is 0 then it's a right-click. When it's 1 then it's a left click.

    Field a is ignored by minecraft as it sets the player that sends the packet as the player that interacted with the entity.

    Now, how is this an answer on your questions? Well I think that at this points it's kinda obvious that you need to listen for incoming packets, with a tool like ProtocolLib, and then filter all the Packet7UseEntity packets out. Check if field b is the id of your npc, if so then check for the action, and so go on.

    Like I said, I created this thread because lately I've seen a lot of people asking this, now, to make some things clear, this is not a support thread. I won't answer any questions about how to use protocolLib to intercept the packets. (if you have any more questions about this that do not involve the "how to intercept" factor then I will be glad to answer them.)

    Lactem and xTrollxDudex like this.
  2. Offline


    You told me to make a variable on this thread. What format would it be? A string a player a entity??
  3. Offline


    This is a bit confuse, but thanks anyway.
    kevinspl2000 likes this.
  4. Offline


    Confusing? How is it confusing?
  5. Offline


    This clears up a lot of things :D
    CaptainBern likes this.
Thread Status:
Not open for further replies.

Share This Page