Jump to content

getPlayers closest player


Recommended Posts

Posted

Hi guys,
I'm into scripting for 2 weeks now and ran into another problem now that I can't seem to solve. Thought I'd ask for help.

I'm trying to make a pker help where I would get all players attacking/surrounding him within 1 tile.

 

Spoiler

   public List<Player> getAttackers() {
        
        List<Player> friends = getPlayers().filter(p -> p != null && edgeArea.contains(p) && friendList.contains(p.getName())); 

        for (Player friend : friends) {
             friend.closest()..                         <<<<<------- this is where I cant get it to work :/ I see that there is no option for this in the API so I obviously can't do this here
        }


        return playersToBePjed;
    }

 

That's the snippet where I cant figure out a way to get the player object next to him

I appreciate all help

Posted
5 hours ago, Panason9c said:

Hi guys,
I'm into scripting for 2 weeks now and ran into another problem now that I can't seem to solve. Thought I'd ask for help.

I'm trying to make a pker help where I would get all players attacking/surrounding him within 1 tile.

private List<Player> getPlayersAttackingPlayer(String playerName, int tileDistanceFromPlayer, ArrayList<String> friendNames){
    Filter<Player> playerFilter = new Filter<Player>() {
        @Override
        public boolean match(Player player) {
            return !player.getName().equals(playerName) && myPlayer().getArea(tileDistanceFromPlayer).contains(player) && !friendNames.contains(player.getName())
                    && (player.getInteracting() != null) && player.getInteracting().getName().equals(playerName);
        }
    };
    return getPlayers().filter(playerFilter);
}

If you are just trying to get one player, use Malcoms method instead, this one will be more performant heavy.

Example Usage

ArrayList<String> friendsNames = new ArrayList<>();
friendsNames.add("Bill");

List<Player> players;

if((players = getPlayersAttackingPlayer(myPlayer().getName(), 20, friendsNames)) != null){
    for(Player player : players){
        log(player.getName());
    }
}
  • 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...