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.

Closest object for an area/point in Osbot2?

Featured Replies

Perhaps I've overlooked something obvious, but despite scouring the Osbot2 API I can't find a method to return an object that is specifically in an area (at a point would work just as well), as

 closestObjectForName(Area, String)  

did in Osbot1.

 

Of course, I suppose I could write my own method to do this, but I'd rather be able to use a built-in method if one exists.

This should do the job ;)

	public static RS2Object getClosest(Script script, String name, String action, Integer minDistance, Integer maxDistance, Area mandatoryArea, Area illegalArea, Position mandatoryPosition, Position illegalPosition, boolean mustBeReachable) {
		RS2Object closestObject = null;
		double lowestDistance = Double.MAX_VALUE;
		List<RS2Object> objectList = script.objects.getAll();
		int size = objectList.size();
		int index = 0;
		for (RS2Object object : objectList) {
			index++;
			if (object == null) {
				continue;
			}
			if (!object.exists()) {
				continue;
			}
			if (!object.getName().toLowerCase().equalsIgnoreCase(name)) {
				continue;
			}
			if (object.getDefinition() == null) {
				continue;
			}
			if (!Arrays.asList(object.getDefinition().getActions()).contains(action)) {
				continue;
			}
			if (minDistance != null && object.getPosition().distance(script.myPosition()) < minDistance) {
				continue;
			}
			if (maxDistance != null && object.getPosition().distance(script.myPosition()) > maxDistance) {
				continue;
			}
			if (mandatoryArea != null && !mandatoryArea.contains(object.getPosition())) {
				continue;
			}
			if (illegalArea != null && illegalArea.contains(object.getPosition())) {
				continue;
			}
			if (mandatoryPosition != null && !object.getPosition().equals(mandatoryPosition)) {
				continue;
			}
			if (illegalPosition != null && object.getPosition().equals(illegalPosition)) {
				continue;
			}
			if (mustBeReachable && !script.map.canReach(object)) {
				continue;
			}
			if (object.getPosition().distance(script.myPosition()) < lowestDistance) {
				closestObject = object;
				lowestDistance = object.getPosition().distance(script.myPosition());
			}
			if (object.getPosition().distance(script.myPosition()) == lowestDistance) {
				if (new Random().nextInt(size - index + 1) == 0) {
					closestObject = object;
					lowestDistance = object.getPosition().distance(script.myPosition());
				}
			}
		}
		return closestObject;
	}

script.objects.closest(new BestMatch(script, name, area));

public class BestMatch implements Filter<RS2Object> {

Script script;

String name;

Area area;

public BestMatch(Script script, String name, Area area) {

this.script = script;

this.name = name;

this.area = area;

}

@Override

public boolean match(RS2Object o) {

return o.getName().equals(name)

&& area.contains(o) && script.map.canReach(o);

}

}

Edited by Eliot

script.objects.closest(new BestMatch(script, name, area));
public class BestMatch implements Filter<RS2Object> {
	Script script;
	String name;
	Area area;

	public BestMatch(Script script, String name, Area area) {
		this.script = script;
		this.name = name;
		this.area = area;
	}

	@Override
	public boolean match(RS2Object o) {
		return o.getName().equals(this.name)
		     && area.contains(o) && script.map.canReach(o);
		}
}

 

objects.closest seems to always return the first loaded object when multiple objects are the closest (have the same distance), I hate that.

objects.closest seems to always return the first loaded object when multiple objects are the closest (have the same distance), I hate that.

This works great for me. 10/10 would use again. :)

This works great for me. 10/10 would use again. smile.png

 

I have no doubts about it's functionality ^^

 

But it's the reason why most people botting are standing at the same bankbooths for example, or will choose the same tree over and over again when standing in between two trees.

 

Not sure if Jagex tracks such behavior, I doubt it actually :p

 

But yeah, just annoys me ph34r.png

I have no doubts about it's functionality ^^

 

But it's the reason why most people botting are standing at the same bankbooths for example, or will choose the same tree over and over again when standing in between two trees.

 

Not sure if Jagex tracks such behavior, I doubt it actually tongue.png

 

But yeah, just annoys me ph34r.png

I use the same bank booth and click on the same trees, so I'm glad my script tends to do the same.

I use the same bank booth and click on the same trees, so I'm glad my script tends to do the same.

 

If 50 bots stand in between two trees and all of them pick the right one over the left one then there's nothing glad about that :p Ah well, I'll keep the left one for myself I guess (a)

  • Author

I'll definitely use this for my current script, as the object I need to find is a single door in a set location; Also, this just taught me how to use filters, so thanks for that.

 

 

 

 


 

However, your method will be very helpful once I move on to the Barrows script I have planned <3

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.