Jump to content

Interacting with another entity if the first entitys condition isnt met


Temsei

Recommended Posts

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!
Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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