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 would i go about grabbing the value of items in my inventory?

Featured Replies

Im trying to grab the total value of all items in my inventory, is there any tutorials or snippets on this? iv used the search but cant find much.

:)

Basically im making a script that kills monsters and loots the items, i need to grab the total loot value to let me know how much money i have made.

 

I have the value of every item the monsters drops and the item name so i do not need to use osbuddy exchange or anything.

I just need to tally up the value of the inventory after every kill.

Edited by shaba123

You can use this to get item prices:

 

Then you would need to make some sort of listener that tracks changes in your inventory. For example store current items in your inventory every time you perform a loot action and then you can use this information to calculate the value. Maybe there's a better way to do it, not sure.

 

If you already have the value of all of the items and you've stored them somewhere, all you need to do is loop through each item in your inventory and add up each value.

for (Item i : getInventory().getItems()) {
	totalValue += valueOfItem(i);
}

 

19 minutes ago, 0x7CB said:

You can use this to get item prices:

 

Then you would need to make some sort of listener that tracks changes in your inventory. For example store current items in your inventory every time you perform a loot action and then you can use this information to calculate the value. Maybe there's a better way to do it, not sure.

 

Only problem with that is it will constantly' open and close the site' to read from. Most likely would notice some slowness.

2 minutes ago, dreameo said:

Only problem with that is it will constantly' open and close the site' to read from. Most likely would notice some slowness.

You could save the prices of what you're going to loot in onStart.

  • Author

So my script is a bit of a mess right now.

On start i grab the prices of around 30 different items from rsbuddy using :

		 item1 = getPrice(1163);
    	 item2 = getPrice(1127);
    	 item3 = getPrice(1079);
    	 item4 = getPrice(1201);
    	 item5 = getPrice(1347);

I have a list of items to loot like so :

String[] itemsToLoot = new String[]{"Bones", "Coins", "Rune longsword", "Rune warhammer"};

So say a monster drops a piece of loot, this time its "Bones" which are looted by item name "Bones" . On my list of prices item1 is the price of Bones.

After i loot the bones how do i tell the script it has looted bones and to add the price of bones to an integer.

 

edit: the only way i can think of is using 

if (getInventory().contains("Bones")) { 

lootValue = lootValue + item1
}

 

edit: if i use the above example, everytime i check the inventory it will see if it contains bones and add the price on again.

Edited by shaba123

  • Author

edit: i think i have worked it out by resetting the lootValue to 0 before checking inventory.

This is what i am using :

 

	public void updateInventoryValue() {
		
		lootValue = 0;
		

		if (getInventory().contains("Dragon 2h sword")) { 

			lootValue = lootValue + drag2H;
			
			}

		log(lootValue);
}

I run that after looting an item. But it wont work properly because what if i looted two dragon 2h swords.

 

There must be a better way of doing this

Edited by shaba123

  • Author
12 hours ago, d0zza said:

If you already have the value of all of the items and you've stored them somewhere, all you need to do is loop through each item in your inventory and add up each value.


for (Item i : getInventory().getItems()) {
	totalValue += valueOfItem(i);
}

 

Hi mate thanks for this reply, im trying to put this into practice but really struggling.

My list of item values if like this :

		runeFH = getPrice(1163);
    	 runePB = getPrice(1127);
    	 runePL = getPrice(1079);
    	 runeKS = getPrice(1201);

Im grabbing the values from osbuddy which is working fine.

How can i assign the prices to their itemId so i can use your example.

4 minutes ago, shaba123 said:

Hi mate thanks for this reply, im trying to put this into practice but really struggling.

My list of item values if like this :


		runeFH = getPrice(1163);
    	 runePB = getPrice(1127);
    	 runePL = getPrice(1079);
    	 runeKS = getPrice(1201);

Im grabbing the values from osbuddy which is working fine.

How can i assign the prices to their itemId so i can use your example.

https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html

A HashMap will allow you to link an item or String (item name) to a particular integer (item value).

  • Author
8 hours ago, d0zza said:

https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html

A HashMap will allow you to link an item or String (item name) to a particular integer (item value).

Hi d0zza

Iv been looking at hashmaps and come up with this :

    	 HashMap<String, Integer> hash = new HashMap<>();
    	 hash.put("Rune full helm", 20000);
         hash.put("Stamina potion(1)", 500);
         hash.put("Rune platelegs", 40000);

I just cant figure out how to link it all together :

for (Item i : getInventory().getItems()) {
	lootValue += hash.get(i);
}

 

34 minutes ago, shaba123 said:

Hi d0zza

Iv been looking at hashmaps and come up with this :


    	 HashMap<String, Integer> hash = new HashMap<>();
    	 hash.put("Rune full helm", 20000);
         hash.put("Stamina potion(1)", 500);
         hash.put("Rune platelegs", 40000);

I just cant figure out how to link it all together :


for (Item i : getInventory().getItems()) {
	lootValue += hash.get(i);
}

 

Right now your key in the for loop when doing hash.get(i) is an Item, you need to use the item's name.

Edited by d0zza

  • Author

so i need to use hash.get("Rune full helm") 

But how do i get the items name from getInventory.getItems and input that where hash.get(i) is .

 

Gahh im so confused.

 

Also my hashmap is in its own void :

    public static void hashing(String args[]) {
    	HashMap<String, Integer> hash = new HashMap<>();

    	
    	hash.put("Rune full helm", 20000);
        hash.put("cat", 2);
        hash.put("rabbit", 3);
        log(hash.get("Rune full helm"));
        }

And in that void it wont let me use getInventory. But out of that void it wont let me use hash.get !

So the hashmap is useless to me

28 minutes ago, shaba123 said:

so i need to use hash.get("Rune full helm") 

But how do i get the items name from getInventory.getItems and input that where hash.get(i) is .

 

Gahh im so confused.

 

Also my hashmap is in its own void :


    public static void hashing(String args[]) {
    	HashMap<String, Integer> hash = new HashMap<>();

    	
    	hash.put("Rune full helm", 20000);
        hash.put("cat", 2);
        hash.put("rabbit", 3);
        log(hash.get("Rune full helm"));
        }

And in that void it wont let me use getInventory. But out of that void it wont let me use hash.get !

So the hashmap is useless to me

The hashmap is not useless to you, you're just not using it properly. Please read up on the basics of Java and OO before trying to script.

  • Author

Yeah i mean its useless to ME not everyone , i know i cant use it properly. Okay thanks

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.