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.

item.getName().startsWith("Stamina potion") - Find in order of dose

Featured Replies

I'm using the following as an example to find any Stamina pots in my bank:

if (getBank().contains(item -> item.getName().startsWith("Stamina potion"))) {
	if (getBank.withdraw(item -> item.getName().startsWith("Stamina potion"), 1)) {
		// This always withdraws the first match, which in my case is Stamina potion(4) (I assume this is because it's the first stamina pot in my bank).
	}
}

How would I instead find the lowest dose potion first, without reordering the bank.

Thanks!

Try using a comparator to re-order an array of the possible potion names.

 

String[] staminaPots=  { "stamina (4)", "stamina (3)", etc };

Arrays.asList(staminaPots).stream().sorted((s1, s2) -> s1.compareTo(s2)) //sorts the potions using natural order i believe

 

Then withdraw the first element of the list if it's not null and bank contains, etc.

1 hour ago, harrypotter said:

I'm using the following as an example to find any Stamina pots in my bank:


if (getBank().contains(item -> item.getName().startsWith("Stamina potion"))) {
	if (getBank.withdraw(item -> item.getName().startsWith("Stamina potion"), 1)) {
		// This always withdraws the first match, which in my case is Stamina potion(4) (I assume this is because it's the first stamina pot in my bank).
	}
}

How would I instead find the lowest dose potion first, without reordering the bank.

Thanks!

 

You could try doing something like this if you just want to get a single potion:

Optional<Item> staminaPotion = Arrays.stream(getBank().getItems())
                                     .filter(item -> item != null && item.getName().startsWith("Stamina potion"))
                                     .min(Comparator.comparing(Item::getName));

This snippet will construct a Stream from the array of all items in the bank, filter it so that only the items which are not null and has a name beginning with "Stamina potion" remain, and then find the min of those using a Comparator to compare the Item names, this should return Stamina potion (1) first etc.

Note: it returns an Optional<Item>, the Optional class can be found here

You use it like so:

if (staminaPotion.isPresent()) {
    Item pot = staminaPotion.get();
}

 

Or to get the List of all stamina potions in the bank, sorted by dosage:

List<Item> staminaPotion = Arrays.stream(getBank().getItems())
                                 .filter(item -> item != null && item.getName().startsWith("Stamina potion"))
                                 .sorted(Comparator.comparing(Item::getName))
                                 .collect(Collectors.toList());

This snippet is similar to the above, but instead of returning the min, it instead sorts the Stream using the same Comparator, and then collects the Items into a List

Edited by Explv

5 minutes ago, Explv said:

 

You could try doing something like this if you just want to get a single potion:


Optional<Item> staminaPotion = Arrays.stream(getBank().getItems())
                                     .filter(item -> item != null && item.getName().startsWith("Stamina potion"))
                                     .min(Comparator.comparing(Item::getName));

Or to get the List of all stamina potions in the bank, sorted by dosage:


List<Item> staminaPotion = Arrays.stream(getBank().getItems())
                                 .filter(item -> item != null && item.getName().startsWith("Stamina potion"))
                                 .sorted(Comparator.comparing(Item::getName))
                                 .collect(Collectors.toList());

 

Dang gonna confuse the man with all that Java 8 lol.

The way I'd do it is just a simple for loop, looping from 1 -> 4,

for(int i = 1; i < 5; i++) {
	String potionName = "Stamina potion(" + i + ")";
	if (getBank().contains(potionName) {
		getBank().withdraw(potionName);
	}
}

 

1 hour ago, Explv said:

 

 

You'd make a good teacher, unlike me you can explain things in a concise and understandable way

2 minutes ago, Tom said:

You'd make a good teacher, unlike me you can explain things in a concise and understandable way

Thanks boss 

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.