Jump to content

Getting all object in a range


Recommended Posts

Posted (edited)

To get every object, you'll need to use streams:

int rad = 10;
String name = "bird snare"; //case doesn't matter
List<Entity> list = getObjects().getAll().stream().filter((e) -> (e != null && e.exists() && e.getName().equalsIgnoreCase(name) && getMap().distance(e) <= rad)).collect(Collectors.toList());

Take a look at my streams tutorial to learn more.

 
 
 
EDIT: getObjects() also has a filter() method, however I prefer streams.
Edited by Bobrocket
  • Like 1
Posted
List<RS2Object> objs = getObjects().filter(o -> myPosition().distance(o) < 10 && "Bird snare".equals(o.getName()));

Thanks for the code but getting error on the ( -> )  , osbot syntax error on "-" -- expected.

 

Does "o" supposed have value?

or do i have to import something?

 

(Srry, I'm not to familiar with these types of complicated code in OSbot)

Posted

Thanks for the code but getting error on the ( -> )  , osbot syntax error on "-" -- expected.

 

Does "o" supposed have value?

or do i have to import something?

 

(Srry, I'm not to familiar with these types of complicated code in OSbot)

 

Like soldtodie said, you have to install Java 8, and set the source version of your project to 8

 

  • Like 1
  • 2 weeks later...

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