Jump to content

Amount of people around entity


lrdblk

Recommended Posts

 

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