Jump to content

Looping a area for objects


BloodRush20

Recommended Posts

As simple as it sounds from the title, How would I go about looping thought all the objects in a area and getting the amount of certain objects

 

Example in my area woodcutting there are 4 trees that are yew. but once one is cut down the object id changes so How can I loop through to see how many yews are left in the area.

 

Id assume some type of for loop but I haven't attempted anything like this on osbot so help would be greatly appropriated!

 

Edit: to be clear I'm not concerned with storing the positions or anything I just need a number count

Edited by BloodRush20
Link to comment
Share on other sites

As simple as it sounds from the title, How would I go about looping thought all the objects in a area and getting the amount of certain objects

 

Example in my area woodcutting there are 4 trees that are yew. but once one is cut down the object id changes so How can I loop through to see how many yews are left in the area.

 

Id assume some type of for loop but I haven't attempted anything like this on osbot so help would be greatly appropriated!

 

Edit: to be clear I'm not concerned with storing the positions or anything I just need a number count

 

Any reason why you need to do this?

 

If you want it to move to a different area if no trees are available then you can do

Entity yew = objects.closest("Yew tree");
if(yew==null)
localWalker.walkPath(toOtherTrees);
Link to comment
Share on other sites

use the filter api, It returns a list. Using the list size to get amount of entity in area.

Basically use a void it establish an int using the filter to grab the object inside my area? sorry not used filters much outside of the basic objects closest or inventory and such

 

 

Any reason why you need to do this?

 

If you want it to move to a different area if no trees are available then you can do

Entity yew = objects.closest("Yew tree");
if(yew==null)
localWalker.walkPath(toOtherTrees);

I understand walking to a new area but thats not my point I need the amount of X in any area I select honestly it has multiple uses hunter woodcutting, combat scripts, HUD script, idk ect. Say since ur the hunter man lately you set a area for chins then you wanna keep track of how many boxes are down in your area the boxes are the X but simply grabbing the closest wont return all the ones in the area. Then you can use the amount given at the time for Paint or a check, ect.

Edited by BloodRush20
Link to comment
Share on other sites

I understand walking to a new area but thatch not my point I need the amount of X in any area I select honestly it has multiple uses hunter woodcutting, combat scripts, HUD script, idk ect. Say since ur the hunter man lately you set a area for chins then you wanna keep track of how many boxes are down in your area the boxes are the X but simply grabbing the closest wont return all the ones in the area. Then you can use the amount given at the time for Paint or a check, ect.

 

Well for the hunter one, I'd place down a trap, then i'd store that trap I placed down into a position, so that way it will only interact with my traps.

Link to comment
Share on other sites

As simple as it sounds from the title, How would I go about looping thought all the objects in a area and getting the amount of certain objects

 

Example in my area woodcutting there are 4 trees that are yew. but once one is cut down the object id changes so How can I loop through to see how many yews are left in the area.

 

Id assume some type of for loop but I haven't attempted anything like this on osbot so help would be greatly appropriated!

 

Edit: to be clear I'm not concerned with storing the positions or anything I just need a number count

  int howManyObjects(String objectName, Area area){
        java.util.List<RS2Object> allObjects = objects.getAll();
        java.util.List<RS2Object> instancesOfObject = new LinkedList<>();
        
        for(RS2Object i : allObjects){
            if(i.getName().equals(objectName) && area.contains(i)){
                instancesOfObject.add(i);
            }
        }
        return instancesOfObject.size();
    }
Link to comment
Share on other sites

Basically use a void it establish an int using the filter to grab the object inside my area? sorry not used filters much outside of the basic objects closest or inventory and such

 

I understand walking to a new area but thats not my point I need the amount of X in any area I select honestly it has multiple uses hunter woodcutting, combat scripts, HUD script, idk ect. Say since ur the hunter man lately you set a area for chins then you wanna keep track of how many boxes are down in your area the boxes are the X but simply grabbing the closest wont return all the ones in the area. Then you can use the amount given at the time for Paint or a check, ect.

no look create a filter.

 

RS2Object already extend FilterAPI so all you have to do is. 

 

getObjects()#filter(YOUR_FILTER) <~~~ it returns a list of the enitty. Then you do a simple size() method to get the amount of entity the list has.

  int howManyObjects(String objectName, Area area){
        java.util.List<RS2Object> allObjects = objects.getAll();
        java.util.List<RS2Object> instancesOfObject = new LinkedList<>();
        
        for(RS2Object i : allObjects){
            if(i.getName().equals(objectName) && area.contains(i)){
                instancesOfObject.add(i);
            }
        }
        return instancesOfObject.size();
    }

use a filter for that. Op: what he did^^^

Link to comment
Share on other sites

no look create a filter.

 

RS2Object already extend FilterAPI so all you have to do is. 

 

getObjects()#filter(YOUR_FILTER) <~~~ it returns a list of the enitty. Then you do a simple size() method to get the amount of entity the list has.

use a filter for that. Op: what he did^^^

ahh your method look fancier

int howManyObjectsOther(final String objectName, Area area){
       return getObjects().filter(new Filter<RS2Object>() {
           @Override
           public boolean match(RS2Object object) {
               return object != null && object.getName().equals(objectName) && area.contains(object);
           }
       }).size();
    }
  • Like 1
Link to comment
Share on other sites

no look create a filter.

 

RS2Object already extend FilterAPI so all you have to do is. 

 

getObjects()#filter(YOUR_FILTER) <~~~ it returns a list of the enitty. Then you do a simple size() method to get the amount of entity the list has.

use a filter for that. Op: what he did^^^

 

 

 

ahh your method look fancier

int howManyObjectsOther(final String objectName, Area area){
       return getObjects().filter(new Filter<RS2Object>() {
           @Override
           public boolean match(RS2Object object) {
               return object != null && object.getName().equals(objectName) && area.contains(object);
           }
       }).size();
    }

Thank you both I will try this after dinner and it looks great glad I can learn something new today! I will call it int IsolateAmount haha

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