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 can i detect if players are nearby?

Featured Replies

I searched through all of the snippets and didn't find anything of interest.

I need to know how to detect if a player is in the same area as me.

:)

public int playerCounter(Area area) {
int players = 0;
for (Player p : this.client.getLocalPlayers()) {
if (p != null && area.contains(p) && p != this.client.getMyPlayer()) {
players++;
}
}
return players;
}

 

smile.png

public int playerCounter(Area area) {
     int players = 0;
     for (Player p : this.client.getLocalPlayers()) {
          if (p != null && area.contains(p) && !p.equals(this.myPlayer())) {
               players++;
          }
     }
     return players;
}

 

Sorry I'm OCD about this. Use .equals() when comparing Object types, instead of != or == when not checking for null. With Integral types it's fine.

Sorry I'm OCD about this. Use .equals() when comparing Object types, instead of != or == when not checking for null. With Integral types it's fine.

 

As in !p.equals(null) ?

I never use .equals() for null checks mellow.png

Now I've got another thing to OCD about myself ph34r.png

Edited by Botrepreneur

As in !p.equals(null) ?

I never use .equals() for null checks mellow.png

Now I've got another thing to OCD about myself ph34r.png

 

No I mean the opposite. It's okay to check for null and integral types(int, float, double, etc.) using == or !=. But when checking Object types use .equals().

 

Edited by NotoriousPP

No I mean the opposite. It's okay to check for null and integral types(int, float, double, etc.) using == or !=. But when checking Object types use .equals().

 

Change this:

 

p != this.client.getMyPlayer()

 

to

 

!p.equals(client.getMyPlayer())

Edited by Pandemic

I generally use ==, != to compare primitive data-type, int, char, boolean etc.

 

For Non-primitive/Objects  - Use .equals()

Not everything has to be in he snippet. Snippets are for more advance stuff. You could also check the issues sub-forum. Something someone might have the same question. And another person could answer for them. Here a link: http://osbot.org/forum/topic/46118-following-players/

That method give you a list of people in your area not including your self. You can simply do getPlayer(area).size > 0

Edited by josedpay

Issue is resolved. Thanks guys :).

 

Guest
This topic is now closed to further replies.

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.