BloodRush20 Posted April 4, 2015 Share Posted April 4, 2015 (edited) 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 April 4, 2015 by BloodRush20 Quote Link to comment Share on other sites More sharing options...
Twin Posted April 4, 2015 Share Posted April 4, 2015 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); Quote Link to comment Share on other sites More sharing options...
Joseph Posted April 4, 2015 Share Posted April 4, 2015 use the filter api, It returns a list. Using the list size to get amount of entity in area. Quote Link to comment Share on other sites More sharing options...
BloodRush20 Posted April 4, 2015 Author Share Posted April 4, 2015 (edited) 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 April 4, 2015 by BloodRush20 Quote Link to comment Share on other sites More sharing options...
Twin Posted April 4, 2015 Share Posted April 4, 2015 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. Quote Link to comment Share on other sites More sharing options...
Isolate Posted April 4, 2015 Share Posted April 4, 2015 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(); } Quote Link to comment Share on other sites More sharing options...
Joseph Posted April 4, 2015 Share Posted April 4, 2015 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^^^ Quote Link to comment Share on other sites More sharing options...
Isolate Posted April 4, 2015 Share Posted April 4, 2015 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(); } 1 Quote Link to comment Share on other sites More sharing options...
BloodRush20 Posted April 4, 2015 Author Share Posted April 4, 2015 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 Quote Link to comment Share on other sites More sharing options...