Jump to content

Amount of people around entity


Recommended Posts

Posted

 

I made this snippet for my wood cutter.  You can use the code to check how many people are surrounding any entity.  

First import

import static java.lang.Math.toIntExact;

Here is the snippet.  

e = the entity you are checking

areaSize = the size of the area around the entity you want to check.

private int peopleAroundEntity (Entity e, int areaSize){
        return toIntExact(players.getAll().stream().filter(x -> e.getArea(areaSize).contains(x)).count());
    }

And this is how I used the snippet

private Predicate<RS2Object> bestTree = tree ->
            tree != null &&
            chopArea.contains(tree) &&
            tree.getName().equalsIgnoreCase(treeType) &&
            tree.hasAction("Chop down") &&
            peopleAroundEntity(tree, 2) <= 3;

java.util.List<RS2Object> tree = getObjects().getAll().stream().filter(bestTree).collect(Collectors.toList());

Then from there you can sort the list as you want. For this script, I have it sorted by distance

tree.sort(Comparator.<RS2Object>comparingInt(a -> getMap().realDistance(a))
                                .thenComparingInt(b -> getMap().realDistance(b)));

The whole script can be found on my github

https://github.com/MeatRainbow/Wood_Chopper

 

Hope this helps someone

  • Like 2

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