NPC's heads

Discussion in 'Plugin Development' started by Xandaros, Apr 24, 2012.

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

    Xandaros

    Hey guys,
    I really need help on this one.

    I am currently developing a NPC plugin and I can't get my NPCs to look in the direction I want them to.

    The problem is:
    Have you ever looked at a player who is afK?
    If you just loaded him(teleporting/rejoining) he will be looking south. The same direction all my NPCs are looking.

    Now, the EntityLiving class has a field called "X". Setting it, will set the head of the NPC.
    However, this will not last. As soon as you relog or go far away the NPC will be looking south again.
    And he won't look into another direction unless it is at least 6° different from the previous direction he was looking in.

    Therefore, all my NPCs are shaking their head currently.

    I've looked thoroughly through Citizens and npcx, but other than setting this field (Citizens 2 doesn't even do that), I couldn't find anything.

    So how do I make them look in one direction without shaking their heads?
    Seems hard to me, because usual players behave the same way...

    I was looking into this for 3 days now, I hope you can help me..
     
  2. Offline

    SirTyler

    Are you using NPCLib or doing this by yourself?
     
  3. Offline

    Xandaros

    I'm doing it by myself
     
  4. Offline

    SirTyler

    Then look at the code NPCLib uses, I don't know how much it will help you but it will give you an idea.
     
  5. Offline

    Xandaros

    Started doing that as soon as I read your previous post.
    I noticed NPCLib doesn't do anything different, so I made a little test plugin.

    The NPCs behave exactly the same way mine do: looking south...
     
  6. Offline

    SirTyler

    They have a lookAtPoint(Location) method you should look at.
     
  7. Offline

    Xandaros

    It works if I am standing right beside it, but as soon as I relog, they are facing south again.
    The same with my NPCs...

    I'm starting to think that it's impossible...
    My friend told me that Citizens handles it correctly, though... But I haven't seen it myself.
    Either way, Citizens code didn't help me anyhow...
     
  8. Offline

    Cornyfisch

    Maybe you use the onPlayerJoin function for setting the head's directing when a player logged in. Only an idea!
     
  9. Offline

    Xandaros

    I thought about that.
    However, this idea has some flaws:
    - The head also faces south if you were far away. (You don't need to be that far away, though. You don't have to leave sight radius)
    - You can only change the head direction, you can't refresh it. Changing it to the same or only slightly different value yields no effect.

    What I just thought about:
    There has to be a packet that tells the other players that one Player(NPC) moved their head.
    I could periodically send this packet to players in range.
    If the head appears wrongly, it fixes itself after a set amount of time. (Thinking of 2 seconds here)

    However, I couldn't find this packet yet.
    All I found was Packet10Flying, but that changes my own direction... :D

    Edit:
    Found it: Packet35EntityHeadRotation
    Works like a charm.

    Thanks for your efforts!
     
  10. Offline

    isaaces

    Then look at the code NPCLib uses.[​IMG]
     
  11. Offline

    Feed_Dante

    Xandaros
    The head yaw for EntityLiving is X
    after entity.lookAtPoint(loc) use
    entity.X = entity.yaw

    NPCLib last I checked will NOT do this properly, I needed to add it myself

    PS: The line I added to NPCLib's lookAtPoint(loc) was this:
    ((EntityLiving) getEntity()).X = getEntity().yaw;
     
  12. My PR, which I made a week ago or something, got accepted yesterday so the lib will now do that.
     
Thread Status:
Not open for further replies.

Share This Page