Events Happening near an NPC

Discussion in 'Plugin Development' started by xxCoderForLifexx, May 28, 2013.

Thread Status:
Not open for further replies.
  1. When a player is near a NPC how can I make an event happen?
     
  2. Offline

    Garris0n

    On playermoveevent do a getNearbyEntities() check and see if one is a villager...I'm sure there are other ways, that's just the first one that came to mind.
     
  3. Okay I will try this.
     
  4. Offline

    Garris0n

    I'd be careful getNearbyEntities may be to intensive for a playerMoveEvent and cause lag.
     
  5. I did experience a bit of lag when I tested it I will see if I can find a safer way to to it.
     
  6. Offline

    Garris0n

  7. I am using it so you can talk to NPC's. Like an AI almost. But they will be activated by "key words".
     
  8. Offline

    Garris0n

    Are these npcs going to be known to you? Because you could do a check for distance on the move event(I would assume that's less intensive). Not sure if that was confusing, but I mean onPlayerMove if(player.getLocation().distance(npc's location) < 10){ talk to player}\

    Edit: http://jd.bukkit.org/rb/apidocs/src-html/org/bukkit/Location.html#line.363
    I'm no expert in optimization but that probably won't lag. Test it.
     
Thread Status:
Not open for further replies.

Share This Page