Jump to content

getPlayers closest player


Panason9c

Recommended Posts

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

Link to comment
Share on other sites

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