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.

Get all the objects of in ID inside an area.

Featured Replies

I'm trying to get all the objects of various id's inside an area.

I was trying to

getObjects().filter(new IdFilter(id),new AreaFilter(area));

But getting many repeated objects?

 

Another question:

 

For example, when i chop a tree, and i have an object, when it grows up, is the same object with different model, or is a new object

Edited by maxibaby

There are 2 ways to do this

 

1. Using OSBot Filter API

List<RS2Object> objs = objects.filter(new Filter<RS2Object>() {
			@Override
			public boolean match(RS2Object o) {
				return o.getId() == ID && AREA.contains(o);
			}
		});

2. Using lambda expressions

RS2Object[] objs = objects.getAll().stream().filter(o -> o.getId() == ID && AREA.contains(o)).toArray(RS2Object[]::new);

First one returns a list, while the second returns an array. That doesn't make much difference if you know how to use them.

 

As for your second question, I'm pretty sure it's the same object, hence we have an exists() method in the API which is used to check if that object still exists.

RS2Object[] objs = objects.getAll().stream().filter(o -> o.getId() == ID && AREA.contains(o)).toArray(RS2Object[]::new);

 

 

This can be done in a shorter way:

RS2Object[] objects = getObjects().filter(obj -> obj.getId() == ID && AREA.contains(obj));

Usually what you want to do is find the closest object, for example to find the closest Willow tree in a specified Area:

RS2Object willowTree = getObjects().closest(obj -> obj.getName().equals("Willow") && AREA.contains(obj));

Edited by Explv

Can you please explain to me what are you doing.

 

From what i read on api

 

http://osbot.org/api/org/osbot/rs07/api/filter/FilterAPI.html#filter-java.util.Collection-org.osbot.rs07.api.filter.Filter...-

 

Signature is 

filter(Filter<E>... filters)

So, what are you guys passing as parameter?

 

 

I am just using lambda expressions as it shortens your code significantly: http://tutorials.jenkov.com/java/lambda-expressions.html

 

This:

getObjects().filter(obj -> obj.getId() == ID && AREA.contains(obj));

Is equivalent to:

getObjects().filter(new Filter<RS2Object>() {
    @Override
    public boolean match(RS2Object obj) {

        return obj.getId() == ID && AREA.contains(obj);
    }
});

Edited by Explv

Can you please explain to me what are you doing.

 

From what i read on api

 

http://osbot.org/api/org/osbot/rs07/api/filter/FilterAPI.html#filter-java.util.Collection-org.osbot.rs07.api.filter.Filter...-

 

Signature is 

filter(Filter<E>... filters)

So, what are you guys passing as parameter?

that parameter uses your array of filters not as one but instead separately. It will return the first found filter.

 

for example:

getInventory().getItem(string...array);

will return the first found item by name. 

 

just because you added different 2 filters does not mean it will combine them into one.

RS2Object[] objects = getObjects().closest(obj -> obj.getName().equals("Willow") && AREA.contains(obj));

 

should be RS2Object objects = getObjects()............... the rest. not array

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.