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 tell if there are none of a certain item in an area?

Featured Replies

i basically just need to know how to return a true if there are no "Logs" (or whatever item)  in a given area. or if it would be easier if there are just no grounditems in an area at all, but this may cause future problems.

GroundItem logs = getScript().getGroundItems().closest(

new AreaFilter<GroundItem>(area),

new NameFilter<GroundItem>("Logs"));

if (logs != null) {

// Logs in the area

}

Edited by Lemons

i basically just need to know how to return a true if there are no "Logs" (or whatever item)  in a given area. or if it would be easier if there are just no grounditems in an area at all, but this may cause future problems.

 

Using the OSBot API:

final boolean itemIsInArea(final Area area, final String itemName) {
    return getGroundItems().filter(new AreaFilter<>(area), new NameFilter<>(itemName)).size() > 0;
}

Using the Java 8 Stream API :

final boolean itemIsInArea(final Area area, final String itemName) {
    return getGroundItems().getAll().stream().anyMatch(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem));
}

Using a for loop:

final boolean itemIsInArea(final Area area, final String itemName) {
    for(final GroundItem groundItem : getGroundItems().getAll()) {
        if(groundItem.getName().equals(itemName) && area.contains(groundItem)) {
            return true;
        }
    }
    return false;
}

If you want to get the closest matching item in the area you can do:

 

With the OSBot API:

final Optional<GroundItem> closestItemInArea(final Area area, final String itemName) {
    return Optional.ofNullable(getGroundItems().closest(new AreaFilter<>(area), new NameFilter<>(itemName)));
}

With the Java 8 Stream API:

final Optional<GroundItem> closestItemInArea(final Area area, final String itemName) {
    return getGroundItems().getAll()
                           .stream()
                           .filter(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem))
                           .min((g1, g2) -> Integer.compare(myPosition().distance(g1.getPosition()), myPosition().distance(g2.getPosition())));
}

Or if you want to get any matching item in the area (not necessarily the closest) you can do:

 

With the OSBot API:

final Optional<GroundItem> getItemInArea(final Area area, final String itemName) {
    return Optional.ofNullable(getGroundItems().singleFilter(getGroundItems().getAll(), 
                                                             new AreaFilter<>(area), 
                                                             new NameFilter<>(itemName)));
}

 

With the Java 8 Stream API:

final Optional<GroundItem> getItemInArea(final Area area, final String itemName) {
    return getGroundItems().getAll()
                           .stream()
                           .filter(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem))
                           .findAny();
}

 

Edited by Explv

 

Using the OSBot API:

final boolean itemIsInArea(final Area area, final String itemName) {
    return getGroundItems().filter(new AreaFilter<>(area), new NameFilter<>(itemName)).size() > 0;
}

Using the Java 8 Stream API :

final boolean itemIsInArea(final Area area, final String itemName) {
    return getGroundItems().getAll().stream().anyMatch(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem));
}

Using a for loop:

final boolean itemIsInArea(final Area area, final String itemName) {
    for(final GroundItem groundItem : getGroundItems().getAll()) {
        if(groundItem.getName().equals(itemName) && area.contains(groundItem)) {
            return true;
        }
    }
    return false;
}

If you want to get the closest matching item in the area you can do:

 

With the OSBot API:

final Optional<GroundItem> closestItemInArea(final Area area, final String itemName) {
    return Optional.ofNullable(getGroundItems().closest(new AreaFilter<>(area), new NameFilter<>(itemName)));
}

With the Java 8 Stream API:

final Optional<GroundItem> closestItemInArea(final Area area, final String itemName) {
    return getGroundItems().getAll()
                           .stream()
                           .filter(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem))
                           .min((g1, g2) -> Integer.compare(myPosition().distance(g1.getPosition()), myPosition().distance(g2.getPosition())));
}

Or if you want to get any matching item in the area (not necessarily the closest) you can do:

 

With the OSBot API:

final Optional<GroundItem> getItemInArea(final Area area, final String itemName) {
    return Optional.ofNullable(getGroundItems().singleFilter(getGroundItems().getAll(), 
                                                             new AreaFilter<>(area), 
                                                             new NameFilter<>(itemName)));
}

 

With the Java 8 Stream API:

final Optional<GroundItem> getItemInArea(final Area area, final String itemName) {
    return getGroundItems().getAll()
                           .stream()
                           .filter(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem))
                           .findAny();
}

 

 

What r u doing with ur life mane :boge:

 

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.