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 check if there is players nearby?

Featured Replies

Hi, i have been working on my script for a while now and can't resolve how i can check if there is players nearby? I tried to do something with (AREA.contains(something.....)

Didn't test, but this might work

players.getAll().stream().anyMatch(f -> myPlayer().getArea(5).contains(f));

This will check if there's at least one player around in an area of radius 5 around your player.

Returns a boolean true/false

Edited by nosepicker

Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()));

closest is != null if there is a player within detectable distance (just about the size of the minimap)

4 minutes ago, GPSwap said:

Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()));

closest is != null if there is a player within detectable distance (just about the size of the minimap)

This should actually work quicker than my example.

Adding a lil extra to filter by predefined distance

Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()) && myPlayer.getArea(5).contains(p));

 

  • Author
 public int onLoop() throws InterruptedException {
        if (AREA.contains(myPlayer())) {
            Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()));
            if (closest !=null)
                log("Hopping....");
                 getWorlds().hopToP2PWorld();
                 wait(5000); //freezes here...?
        }else {
             log("Walking");
             if (getWalking().walk(AREA));
             new ConditionalSleep(3000, 1000) {
                 @Override
                 public boolean condition() throws InterruptedException {
                     return (AREA.contains(myPlayer()));
                 }
             }.sleep();
                        }
        return 100;

I tested those and they work. But now I'm trying to compound that script with world hopping.. Any help?

I'm guessing you're trying to find players who are nearby you? If so:

private List<Player> getPlayersNearby(int distance) {
	final Player me = myPlayer();
	return players.filter(p -> !me.equals(p) && me.getPosition().distance(p) <= distance);
}

 

3 hours ago, nosepicker said:

This should actually work quicker than my example.

Adding a lil extra to filter by predefined distance


Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()) && myPlayer.getArea(5).contains(p));

 

You're misusing getArea:

  1. You're creating a new Area object just to test whether someone is inside of it. What a total waste.
  2. You're creating that new Area object for each player you check.

Additionally, the null check is redundant as OSBot won't pass you null values to begin with, and you should cache myPlayer() somewhere, as that's likely a function that interfaces with the game to grab your player information. You should only have to grab it once for the duration of your checking. Otherwise, it's just inefficient.

  • Author
30 minutes ago, liverare said:

I'm guessing you're trying to find players who are nearby you? If so:


private List<Player> getPlayersNearby(int distance) {
	final Player me = myPlayer();
	return players.filter(p -> !me.equals(p) && me.getPosition().distance(p) <= distance);
}

 

Yep or actually trying to check if there's any players nearby if there is the script will hop.. 

4 hours ago, GPSwap said:

Player closest = getPlayers().closest(p -> p != null && !p.equals(myPlayer()));

closest is != null if there is a player within detectable distance (just about the size of the minimap)

or simply !getPlayers().getAll().isEmpty()

Edit: to account for my player just check if size == 1

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.