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.

Get closest player not me

Featured Replies

Here is what I am trying:

 

        Player v = script.myPlayer()
        Player closestPlayer = script.getPlayers().closest((Filter<Player>)(v));
         if (closestPlayer != null){
         
         script.log("Closesat player is " + closestPlayer);
         }else {
             script.log("No one nearby");
         }

 

But I am getting this error in the log:

[ERROR][Bot #1][08/06 02:11:18 PM]: Error in script executor!
java.lang.ClassCastException: org.osbot.rs07.api.model.Player cannot be cast to org.osbot.rs07.api.filter.Filter

 

 

Any help here would be appreciated.

 

 

 

Doing (Filter<Player>) makes it so you cast to that data type but what you are looking for is something like script.getPlayers().closest(n -> !n.getName().equals(script.myPlayer().getName()) && n != null);

Closest player that's not you:

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

You could also compare their names, but I believe equals() has been implemented for players :) 

1 minute ago, IDontEvenBot said:

Doing (Filter<Player>) makes it so you cast to that data type but what you are looking for is something like script.getPlayers().closest(n -> !n.getName().equals(script.myPlayer().getName()) && n != null);

If you're going to null check, put the null check before you use the object's reference...

Edited by Imateamcape

Close, you're not using filters quite right. Try something more like this

        Player closest = players.closest((Filter<Player>) player -> !player.getName().equals(myPlayer().getName()));

 

  • Author

Thanks. In all the above examples I get variable can't be resolved (n p whichever I use) and a syntax error on -> (it says - or -- expected).

 

I suspect this has something to do with the structure of my script, having to add "script." as a prefix to most everything. That's pretty much how I "learned", I took someone else's script and modified to do what I want.

27 minutes ago, Imateamcape said:

Closest player that's not you:

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

You could also compare their names, but I believe equals() has been implemented for players :) 

If you're going to null check, put the null check before you use the object's reference...

using equals method is best suited for strings, it's not good to compare objects otherwise like that.

 

String s =  new String("hello");

String p = new String("hello");

s.equals(p) // true

s == p // false;

 

44 minutes ago, sudoinit6 said:

Thanks. In all the above examples I get variable can't be resolved (n p whichever I use) and a syntax error on -> (it says - or -- expected).

 

I suspect this has something to do with the structure of my script, having to add "script." as a prefix to most everything. That's pretty much how I "learned", I took someone else's script and modified to do what I want.

replace it with this then:

 

Player closest = getPlayers().closest(new Filter<Player>() {

                  @Override

                   public boolean match(Player p) {

                        return p != null && !p.equals(myPlayer());

                   }

});

 

If that works for you, but the other doesn't, that means that you don't have Java 8 downloaded (so you can't use Lambda).

  • Author
28 minutes ago, Imateamcape said:

replace it with this then:

 

Player closest = getPlayers().closest(new Filter<Player>() {

                  @Override

                   public boolean match(Player p) {

                        return p != null && !p.equals(myPlayer());

                   }

});

 

If that works for you, but the other doesn't, that means that you don't have Java 8 downloaded (so you can't use Lambda).

Thank you so much cape! This worked  beautifully (after adding a couple "script." pre-fixes).

 

I take back all of the bad things I said about you in chat when you weren't there :)

 

 

 

 

 

1 minute ago, sudoinit6 said:

Thank you so much cape! This worked  beautifully (after adding a couple "script." pre-fixes).

I take back all of the bad things I said about you in chat when you weren't there :)

:) 

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.