Jump to content

Get all the objects of in ID inside an area.


maxibaby

Recommended Posts

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

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.

Link to comment
Share on other sites

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

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?

Edited by maxibaby
Link to comment
Share on other sites

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

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

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