Jump to content

Interacting with another entity if the first entitys condition isnt met


Recommended Posts

Posted

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!
Posted (edited)

 

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
  • Like 3
Posted (edited)

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
Posted (edited)

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
  • Like 2
Posted

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!

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...