Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to know if other players are nearby

Featured Replies

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. 

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

Edited by Pure_

  • Author

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

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

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

 

That method works fine, he just might want to check that the player != myPlayer

Edited by Explv


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

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

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.