Jump to content

finding npc help


Recommended Posts

Area yourArea = new Area(...);
NPC npc = getNpcs().filter(npc -> npc != null && yourArea.contains(npc) && npc.getName().equals("NPC NAME"));


Will work great if the NPC is in the area, bu here's some messy code to walk to npc if it's too far away

Filter npcFilter = new Filter<NPC>() {
			public boolean match(NPC npc) {
				return npc != null && npc.getName().equals("NPC NAME");
		NPC npc = npcs.closest(npcFilter);
		if (npc != null) {
			if (npc.isVisible()) {
			} else {
				Area npcArea = npc.getArea(6); // Radius around the NPC
				if (!npcArea.contains(myPlayer())) {
				} else {
Edited by nosepicker
  • Like 1
Link to comment
Share on other sites


semi-related to this thread, but every time i use id's in my code for npcs it laggs client...

am i doing something wrong in this code?


NPC npc = getNpcs().closest(420);

and before you say to use Filters/names that won't work in this situation.

sorry for being autism



Well two things here that may produce "Lag", though I think you should be getting an error in the logs. First of all check if the ID's are right, then check if the npc is found with if (npc != null) . Then a good idea would be to check if the NPC is visible, cause it won't interact with it the other way (correct me if I'm wrong). And finally, I seriously doubt that an NPC has an action "use". I don't remember the outcome if you use an action that isn't there. Either nothing happens or you'll get an error.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...