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.

Checking if bank contains a list of items?

Featured Replies

I've tried a couple of ways to do this, for example if the bank contains a charged glory or stamina potion, basically I am trying to use the lowest value of charge/stamina before going back to the (6) or (4)

 

Could anyone post a snippet? I've tried searching about, but I am sort of new to lists :(

 

What I have so far:

 

String[] gloryNames = {"Amulet of glory(1)", "Amulet of glory(2)", "Amulet of glory(3)", "Amulet of glory(4)", "Amulet of glory(5)", "Amulet of glory(6)"};
			if (needGlory == true && bank.contains(gloryNames)){ 
	    			new ConditionalSleep(random(5000,7000)) {
			    	public boolean condition() {
			    			if (getBank().withdraw(bank.getSlot(gloryNames),1)) { getStatus = "Withdraw glory";}
			    				return inventory.contains(gloryNames.toString());
			    			}
			    		}.sleep();
			    		inventory.interact(inventory.getSlot(gloryNames.toString()), "Wear");
	    			}

 

Edited by OllieW

you could just use multiple else if? I dont know if thats really inefficient tho

  • Author
1 minute ago, Abysm said:

you could just use multiple else if? I dont know if thats really inefficient tho

 

Thats why I was avoiding that, I am certain there's a better way :\ will use that for now I guess

19 minutes ago, OllieW said:

 

Thats why I was avoiding that, I am certain there's a better way :\ will use that for now I guess

Optional<Item> gloryNames= Arrays.stream(getInventory().getItems()).filter(i -> i != null && (i.nameContains("Amulet of glory(1)") || i.nameContains("Amulet of glory(2)"))).findFirst();

 

Try This 

zz

 

Just use a for loop,

if need glory and bank open

iterate through the glory strings (1,...6)

if has glory, withdraw (cond sleep)

if inv contains a glory, break the for loop

need glory bool should be flase now

  • Author
18 minutes ago, dreameo said:

zz

 

Just use a for loop,

if need glory and bank open

iterate through the glory strings (1,...6)

if has glory, withdraw (cond sleep)

if inv contains a glory, break the for loop

need glory bool should be flase now

Sorry4noob but can you give an example? I haven't used for loops very much, understand how they work but don't understand how they would work in this instance.

You could try doing something like:

Optional<Item> glory = Arrays.stream(getBank().getItems()).filter(item -> item.getName().startsWith("Amulet of glory(")).min((g1, g2) -> g1.getName().compareTo(g2.getName()))

 

Sorry for any syntax errors, on phone

12 minutes ago, OllieW said:

Sorry4noob but can you give an example? I haven't used for loops very much, understand how they work but don't understand how they would work in this instance.

Something like for (String : gloryString) {

if bank contains glory string {

withdraw glory

}

}

 

 

// assuming bank is open because needGlory is true

String[] glorys = [...]

if(getBank().isOpen)
{
  for(String glory : glorys)
  {
   	if(getBank().contains(glory)
       {
       	 if(getBank().withdraw(glory, 1)
            {
             	cond sleep // inv contains glory
             	break; // exit loop since we have item
              	// needGlory should be false now
            }
       {
  }
            // script should exit here since bank contains no glory
           stop(true);
}

 

Not tested, insert the condition sleep, (maybe few syntax errors idk, just wrote it here)

My favourite thing about programming is that there's literally a million different ways of doing things:

	public void withdrawGlory() {
	
		Item glory = Stream
			.of(bank.getItems())                 // stream of all bank items
			.filter(ScriptName::isAmuletOfGlory) // filter for glories
			.findFirst()                         // get first glory
			.orElse(null);                       // null
		
		if (glory != null) {
			
			// do something
			
		}
	}

	public static boolean isAmuletOfGlory(Item item) {
		return item.getName().contains("glory(");
	}

 

15 minutes ago, liverare said:

My favourite thing about programming is that there's literally a million different ways of doing things:


	public void withdrawGlory() {
	
		Item glory = Stream
			.of(bank.getItems())                 // stream of all bank items
			.filter(ScriptName::isAmuletOfGlory) // filter for glories
			.findFirst()                         // get first glory
			.orElse(null);                       // null
		
		if (glory != null) {
			
			// do something
			
		}
	}

	public static boolean isAmuletOfGlory(Item item) {
		return item.getName().contains("glory(");
	}

 

This would just get any glory, he's looking to prioritize getting glories with the lowest charge (1),(2)...(n)

23 minutes ago, dreameo said:

This would just get any glory, he's looking to prioritize getting glories with the lowest charge (1),(2)...(n)

You can use Explv's "min" statement. It's easy to make the adaptation:

	private void withdrawGlory() {
		Item glory = Stream
			.of(bank.getItems())                    // all bank items
			.filter(ScriptName::isAmuletOfGlory)    // glories only (which includes eternal glory)
			.min(ScriptName::sortByItemName)        // get first glory, but not before sorting them by item name
			.orElse(null);                          // return result glory, or else return null
		
		if (glory != null) {
			
			// do something
			
		}
	}
	
	public static int sortByItemName(Item a, Item b) {
		
		String aa = a.getName();
		String bb = b.getName();
		
		return aa.compareTo(bb);
	}

	public static boolean isAmuletOfGlory(Item item) {
		return item.getName().contains("glory");
	}

 

Edited by liverare

  • Author

Thanks for the replies all, I managed to get it working using @dreameo snippit <3

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.