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.

Return # of players in a certain area

Featured Replies

Right now I am using 
 

getPlayers().getAll().size();

But this only works for the whole loaded map. 
I scoured through the API but cannot find a method to return the number of players within a certain area. 


I am looking for a method that can do something similar to this:  getPlayers().getAll(area).size();

Appreciate any help I can get :)

	public boolean checkforPlayers(Area area) {
        List<Player> playerss = players.getAll();
        for (Player p : playerss) {
            if (area.contains(p) && !p.getName().equals(myPlayer().getName())) {
                return true;
            }
        }
        return false;
    }
	

if you want it in one line I think this might work:

getPlayers().filter(player -> area.contains(player)).size();

2 hours ago, TheWind said:

if you want it in one line I think this might work:

getPlayers().filter(player -> area.contains(player)).size();

this^


Remember that NPC and players only get loaded when they are in range. (+-16 tiles)
This is different then gameobjects that get loaded together with the map chunks.
 

Edited by Khaleesi

  • Author
8 hours ago, TheWind said:

if you want it in one line I think this might work:

getPlayers().filter(player -> area.contains(player)).size();

Thanks totally forgot about Lambda expression 

9 hours ago, Juggles said:

looking for a method that can do something similar to this:  getPlayers().getAll(area).size();
 

 

9 hours ago, TheWind said:

if you want it in one line I think this might work: 


getPlayers().filter(player -> area.contains(player)).size();

 

 

I believe this would also work:

getPlayers().filter(new AreaFilter(area)).size();

 

Edited by Explv

16 hours ago, TheWind said:

if you want it in one line I think this might work:

getPlayers().filter(player -> area.contains(player)).size();

If I'm going to do Lambda, I'll stay away from OSBot's filter and just use theirs:

public final int countPlayers(Area area) {
	return (int) players.getAll().stream().filter(area::contains).count();
}

:)

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.