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.

Ground items to list?

Featured Replies

How would I collect a list of the all ground items that I can edit?
Been trying to do this for about 3 hours now with no luck...

 

Basically need to get all the ground items, and then out of all out those remove any items I don't want, and then give me how many items are left within the list.

 

Been trying with List and Collections, but no luck.

Any tips would be great, thanks!

you could use stre/llambda but for for purpose of simplicity:

for (GroundItem g : groundItems.getAll()) {
if (g != null && g.exists()){
//conditions here blah
}
}

apa


List<String> forbiddenNames = Arrays.asList(new String[] { "Bones", "Coins" });

getGroundItems().getAll().stream().filter((gi) -> (gi != null && gi.exists() && !forbiddenNames.contains(gi.getName()))).collect(Collectors.toList());

  • Author
List<String> forbiddenNames = Arrays.asList(new String[] { "Bones", "Coins" });
getGroundItems().getAll().stream().filter((gi) -> (gi != null && gi.exists() && !forbiddenNames.contains(gi.getName()))).collect(Collectors.toList());

This is pretty beast.

Have no idea how it works but I'm going to figure it out.

 

Thank you! :)

 

Thanks apa, too :)

For completeness, the good old filter 

List<GroundItem> list = groundItems.filter(i -> <conditions>)

groundItems.filter(i -> i.getName().equals("name"));

Still prefer this one over java 8 streams cuz it's unreadable.

Edited by Flamezzz

  • Author

For completeness, the good old filter 

List<GroundItem> list = groundItems.filter(i -> <conditions>)

groundItems.filter(i -> i.getName().equals("name"));

Still prefer this one over java 8 streams cuz it's unreadable.

Would I still be able to get the size (how many) of result items using streams as he shows?

This is pretty beast.

Have no idea how it works but I'm going to figure it out.

 

Thank you! smile.png

 

Thanks apa, too smile.png

 

My streams tutorial can somewhat explain what's happening.

 

We filter our GroundItems list to the following conditions:

  • They aren't null (!= null)
  • They exist (.exists())
  • Their names are not in the forbidden list (!forbiddenNames.contains(gi.getName()))

This will return a list with any ground item that isn't Bones or Coins.

  • Author

My streams tutorial can somewhat explain what's happening.

 

We filter our GroundItems list to the following conditions:

  • They aren't null (!= null)
  • They exist (.exists())
  • Their names are not in the forbidden list (!forbiddenNames.contains(gi.getName()))

This will return a list with any ground item that isn't Bones or Coins.

Thank you so much smile.png

 

EDIT: 

Okay, that part works just fine now. (Thank you Bobrocket, you taught me streams today smile.png)

Now I need to get a list of my inventory items but only make sure the list size (or amount of slots I need to clear up) only reaches the size of wanted ground items. 

Note: to put this in context, I only need to check this when my inv is full and my wanted items are on the ground. (simple conditions I don't need help with)

 

Basically, my inventory is full, I have 3 items on the floor that I want, and need to make 3 spaces in my inventory, so I need to remove 3 of the shitty items I have in my inventory.

 

In a simpler form, how would I set a condition to limit the size of the list? (I know how to set the shitty item condition mentioned above).

Or can I get the list, and then trim it to the size of wanted items?

 

Thanks in advance, sorry if I don't explain all this too well.

 

 

Edited by Aviri

Thank you so much smile.png

 

EDIT: 

Okay, that part works just fine now. (Thank you Bobrocket, you taught me streams today smile.png)

Now I need to get a list of my inventory items but only make sure the list size (or amount of slots I need to clear up) only reaches the size of wanted ground items. 

Note: to put this in context, I only need to check this when my inv is full and my wanted items are on the ground. (simple conditions I don't need help with)

 

Basically, my inventory is full, I have 3 items on the floor that I want, and need to make 3 spaces in my inventory, so I need to remove 3 of the shitty items I have in my inventory.

 

In a simpler form, how would I set a condition to limit the size of the list? (I know how to set the shitty item condition mentioned above).

Or can I get the list, and then trim it to the size of wanted items?

 

Thanks in advance, sorry if I don't explain all this too well.

 

List<Item> junk = getInventory().filter(itm -> itm.getName().equals("Junk"));

List<Item> trimmed = (junk.size() > 3) ? junk.subList(0, 3) : junk;

 

Edited by FrostBug

You can also make your list like frost bug did. Then simply grab the list, search it, and remove the item you don't care about. The you will be left with a list of items you want..

  • Author

Yep! Thanks to everyone who helped out. Working perfectly as intended now!

I'm not a professional but I made a version of this that wrote the items in a list on the paint a while back, here's the snippet just because. Even though the problem was already solved.

		List<GroundItem> itemsog = getGroundItems().getAll();
		int count = 0;
		for (int i = 0; i < itemsog.toArray().length; i++) {
			for (int i2 = 0; i2 < itemsog.toArray().length; i2++) {
				if (itemsog.get(i).getName().equalsIgnoreCase(itemsog.get(i2).getName()) && count == 1) {
					itemsog.remove(i2);
					count = 0;
				}
				if (itemsog.get(i).getName().equalsIgnoreCase(itemsog.get(i2).getName()) && count == 0) {
					count = 1;
				}
			}
		}
                g.setFont(new Font("Trebuchet MS", Font.PLAIN, 10);
                g.setColor(Color.WHITE);
		for (int i = 0; i < itemsog.toArray().length; i++) {
			g.drawString(itemsog.get(i).getName(), 8, 30 + (i * 11));
		}

I know it's lazy as hell and doesn't properly use the API but it's something I improvised due to lack of knowledge there was an easier way xD

Even though it's dirty code it works fine and weeds out all duplicate item names and displays them in the top left corner. of the screen in a nice screen space saving list.

Edited by Paradox68

I'm not a professional but I made a version of this that wrote the items in a list on the paint a while back, here's the snippet just because. Even though the problem was already solved.

		List<GroundItem> itemsog = getGroundItems().getAll();
		int count = 0;
		for (int i = 0; i < itemsog.toArray().length; i++) {
			for (int i2 = 0; i2 < itemsog.toArray().length; i2++) {
				if (itemsog.get(i).getName().equalsIgnoreCase(itemsog.get(i2).getName()) && count == 1) {
					itemsog.remove(i2);
					count = 0;
				}
				if (itemsog.get(i).getName().equalsIgnoreCase(itemsog.get(i2).getName()) && count == 0) {
					count = 1;
				}
			}
		}
                g.setFont(new Font("Trebuchet MS", Font.PLAIN, 10);
                g.setColor(Color.WHITE);
		for (int i = 0; i < itemsog.toArray().length; i++) {
			g.drawString(itemsog.get(i).getName(), 8, 30 + (i * 11));
		}

I know it's lazy as hell and doesn't properly use the API but it's something I improvised due to lack of knowledge there was an easier way xD

Even though it's dirty code it works fine and weeds out all duplicate item names and displays them in the top left corner. of the screen in a nice screen space saving list.

 

@OP, if you want a cleaner version of Paradox's code (pretty inefficient, hard to read etc) here you go:

List<GroundItem> groundItems = getGroundItems().getAll().stream().distinct().collect(Collectors.toList());
int j = 0;
groundItems.forEach((gi) -> (g.drawString(gi.getName(), 8, 30 + ((j++) * 11))));

 

@OP, if you want a cleaner version of Paradox's code (pretty inefficient, hard to read etc) here you go:

List<GroundItem> groundItems = getGroundItems().getAll().stream().distinct().collect(Collectors.toList());
int j = 0;
groundItems.forEach((gi) -> (g.drawString(gi.getName(), 8, 30 + ((j++) * 11))));

 

 

I knew there had to be a way to do this in like one line. I just hadn't heard of stream().distinct() method before. Thanks for the info i'll definitely be implementing this method in future scripts.

Edited by Paradox68

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.