Jump to content

How would i go about grabbing the value of items in my inventory?


shaba123

Recommended Posts

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
Link to comment
Share on other sites

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.

 

  • Like 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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).

  • Like 1
Link to comment
Share on other sites

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);
}

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...