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.

Interacting with another entity if the first entitys condition isnt met

Featured Replies

Hey,

 

I have a few preset areas where the script will power chop trees. I don't want the bot to walk out of the preset area and currently have a simple check for cutting trees within the area:

 

if (LEVELING_AREA1.contains(tree) {
tree.interact("Chop down");
}
 
This creates a small problem. If the tree isn't within LEVELING_AREA1, the script will still hover over the tree and proceed to get stuck as it can't chop it down. 
 
How could I make it so it doesn't even attempt to chop the trees down that aren't in the area?
 
Thanks in advance!

 

Hey,

 

I have a few preset areas where the script will power chop trees. I don't want the bot to walk out of the preset area and currently have a simple check for cutting trees within the area:

 

if (LEVELING_AREA1.contains(tree) {
tree.interact("Chop down");
}
 
This creates a small problem. If the tree isn't within LEVELING_AREA1, the script will still hover over the tree and proceed to get stuck as it can't chop it down. 
 
How could I make it so it doesn't even attempt to chop the trees down that aren't in the area?
 
Thanks in advance!

 

 

when attempting to find the closest and most appropriate tree in that area, i would recommend usng a filter like so:

 

 RS2Object tree = script.getObjects().closest(t -> t != null && t.getName().equals("TREE_NAME_HERE") && AREA_NAME_HERE.contains(t));		

this will only find trees in that area.

 

 

Precise.

Edited by Precise

  • Author

when attempting to find the closest and most appropriate tree in that area, i would recommend usng a filter like so:

 

 RS2Object tree = script.getObjects().closest(t -> t != null && t.getName().equals("TREE_NAME_HERE") && AREA_NAME_HERE.contains(t));		

this will only find trees in that area.

 

 

Precise.

 

Thanks a lot! Seems to be working well.

 

Would you mind explaining the steps your code goes through? I'm not fully comprehending it. More specifically this little part here:

(t -> t != null

And why doesn't this

Entity tree = objects.closest("Tree");
if (LEVELING_AREA1.contains(tree) {

}

accomplish the same thing?

Edited by Temsei

Thanks a lot! Seems to be working well.

 

Would you mind explaining the steps your code goes through? I'm not fully comprehending it. More specifically this little part here:

(t -> t != null

And why doesn't this

Entity tree = objects.closest("Tree");
if (LEVELING_AREA1.contains(tree) {

}

accomplish the same thing?

 

Ok so,

 

when you call:

Entity tree = objects.closest("Tree");

You're getting the closest object which matches the name "Tree" and that only. So you could get a tree which is closest to you, but isn't in the area, and so it won't click it.

 

The code i posted finds the closest object using a filter and only gets objects which have the name "Tree" AND are in the area you specified.

 

let me know if i wasn't clear.

 

Edit:

 

here is another example of how you can write it, might be easier to understand:

RS2Object tree = getObjects().closest(new Filter<RS2Object>() {
        @[member=Override]
	public boolean match(RS2Object o) {
	        if(o != null && o.getName().equals("TREE_NAME") && AREA_HERE.contains(o)) {
			return true;
		}
		return false;
	}
});

Precise.

 

Edited by Precise

  • Author

Ok so,

 

when you call:

Entity tree = objects.closest("Tree");

You're getting the closest object which matches the name "Tree" and that only. So you could get a tree which is closest to you, but isn't in the area, and so it won't click it.

 

The code i posted finds the closest object using a filter and only gets objects which have the name "Tree" AND are in the area you specified.

 

let me know if i wasn't clear.

 

Precise.

 

Ahhh, of course. I got it, thanks a lot buddy!

Just going to add in that the API does have a method for this

RS2Object tree = getObjects().closest(AREA_NAME, "Tree"); //finds the closest tree in that area

It's the same as what Precise said, but it's always beneficial to have a solid knowledge of the API as well :)

Create an account or sign in to comment

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.