Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

closestNPC(...)

Featured Replies

From what I can see it doesn't work well if there are two npcs with the same ID at the same position (barbarian fishing, for example)

Here: 

public NPC getNPC(String name) {
		List<NPC> npcs = closestNPCListForName(name);
		for (NPC npc : npcs) {
			if (npc.getName().equalsIgnoreCase(name)
					&& client.getCurrentRegion().contains(npc))
				return npc;
		}
		return null;
	}

just do NPC npc = getNPC("NPC NAME HERE");

 

 

Your welcome. :) Creds to jwiz.

  • Developer

I can't see anything wrong:

 

 
/**
* Returns the closest NPC with the matching ID.
* @param ids The possible npc identifier numbers.
* @return The closest NPC. Returns null if none were found or are reachable.
*/
public NPC closestNPC(int... ids) {
NPC closestNpc = null;
int closestDistance = Integer.MAX_VALUE;
 
for(NPC npc : client.getLocalNPCs()) {
for (int id : ids) {
if(npc.getId() == id) {
int dist = realDistance(npc);
if(dist != -1 && dist < closestDistance) {
closestNpc = npc;
closestDistance = dist;
}
}
}
}
return closestNpc;
}
 

 

Sorry for the bad formatting, it is due the upgrade of the IPB, we'll have it fixed soon.

Here: 

public NPC getNPC(String name) {
		List<NPC> npcs = closestNPCListForName(name);
		for (NPC npc : npcs) {
			if (npc.getName().equalsIgnoreCase(name)
					&& client.getCurrentRegion().contains(npc))
				return npc;
		}
		return null;
	}

just do NPC npc = getNPC("NPC NAME HERE");

 

 

Your welcome. smile.png Creds to jwiz.

 

Isn't this mine?

  • Developer

Can people please stop using the phrase 'it doesn't work'? The last 10 times I've heard that method were used in the wrong way. Instead, could you please tell me how you are using this method etc?

  • Author

		NPC fishingSpot = closestNPC(2722);

if (fishingSpot != null) {

if (canReach(fishingSpot)) {

selectEntityOption(fishingSpot, "Use-rod");

state = State.FISHING;

} else {

walk(fishingSpot.getPosition());

}

}

Edited by Aeterna

  • Developer

Use this for now, this is a specific problem with fishing spots.

 

/**
* Returns the closest NPC with the matching ID.
* @param ids The possible npc identifier numbers.
* @return The closest NPC. Returns null if none were found or are reachable.
*/
public NPC closestNPC(int... ids) {
NPC closestNpc = null;
int closestDistance = Integer.MAX_VALUE;
 
for(NPC npc : client.getLocalNPCs()) {
for (int id : ids) {
if(npc.getId() == id) {
int dist = distance(npc);
if(dist != -1 && dist < closestDistance) {
closestNpc = npc;
closestDistance = dist;
}
}
}
}
return closestNpc;
}
Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.