Jump to content

How to know if other players are nearby


TheGreatPani

Recommended Posts

Idk how MethodProvider works so i took out the "methods.". The code was also picking up my character and going into the if statement so I changed the if condition to 

if ((p.getPosition().distance(myPlayer().getPosition()) > 1) && (p.getPosition().distance(myPlayer().getPosition()) < 20)  )

Thanks!

Edited by TheGreatPani
Link to comment
Share on other sites

Idk how MethodProvider works so i took out the "methods.". The code was also picking up my character and going into the if statement so I changed the if condition to 

if ((p.getPosition().distance(myPlayer().getPosition()) > 1) && (p.getPosition().distance(myPlayer().getPosition()) < 20)  )

Thanks!

//why not

!p.getname#equals(your acc)
Link to comment
Share on other sites

for (Player p : methods.getPlayers().getAll()) {
            if (p.isVisible() || p.getPosition().distance(methods.myPlayer().getPosition()) < 10) {
                // OH NOES
            }
        }
}

where methods is an instance of MethodProvider

note: i did not test this

 

accully u cant use this method for do, yuo must use recurse method to loop through for player

Link to comment
Share on other sites


// Set maximum distance.

private final int maximumDistance = 12;

/*

Create filter.

Player must:

- Not be null.

- Exist.

- Be within the maximum distance from my player.

*/

private final Filter<Player> filter = player -> player != null && player.exists() && (player.getPosition().distance(myPlayer.getPosition()) < maximumDistance );

// ...

/*

To check if one or more players are nearby:

Apply filter to Players instance.

Check if the result set is greater than 1.

(myPlayer itself will always be part of the result set).

*/

if(getPlayers().filter(filter).size() > 1) {

// There are players nearby.

}

// ...

/*

To get the amount of players nearby:

Apply filter to Players instance.

Subtract 1 from the result set.

(myPlayer itself will always be part of the result set).

*/

int nearby = getPlayers().filter(filter).size() - 1;

Edited by Botre
Link to comment
Share on other sites

I'm trying to make my script log out when any player is in my vicinity. I think I have to use the "getAll()" method in the Players class in the API to do this, but I can't figure out how to write it. Also, will the list be true, full, or something else if there is another player nearby? Thanks. 

 

If you want to check if a player is less than a certain distance away, you can use:

private boolean isOtherPlayerWithinDistance(final int distance) {
    for(final Player player : getPlayers().getAll()) {
        if(player != myPlayer() && player.getPosition().distance(myPosition()) < distance) {
            return true;
        }
    }
    return false;
}

Or you can use a filter:

private boolean isOtherPlayerWithinDistance(final int distance) {
    return !getPlayers().filter(player -> player != myPlayer() && 
                                player.getPosition().distance(myPosition()) < distance).isEmpty();
}

Otherwise you can just check the size of getPlayers().getAll()

private boolean isOtherPlayerNearby() {
    return getPlayers().getAll().size() > 1;
}
Edited by Explv
  • 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...