Jump to content

finding npc help


Recommended Posts

Posted (edited)
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()) {
				//Interact
			} else {
				Area npcArea = npc.getArea(6); // Radius around the NPC
				if (!npcArea.contains(myPlayer())) {
					walking.walk(npcArea);
				} else {
					camera.toEntity(npc);
				}
			}
			
		}
Edited by nosepicker
  • Like 1
Posted

 

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);
npc.interact("use");

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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