shaba123 Posted May 21, 2018 Share Posted May 21, 2018 (edited) 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 May 21, 2018 by shaba123 Quote Link to comment Share on other sites More sharing options...
0x7CB Posted May 21, 2018 Share Posted May 21, 2018 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. 1 Quote Link to comment Share on other sites More sharing options...
d0zza Posted May 21, 2018 Share Posted May 21, 2018 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); } 1 Quote Link to comment Share on other sites More sharing options...
dreameo Posted May 21, 2018 Share Posted May 21, 2018 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. Quote Link to comment Share on other sites More sharing options...
0x7CB Posted May 21, 2018 Share Posted May 21, 2018 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. Quote Link to comment Share on other sites More sharing options...
shaba123 Posted May 21, 2018 Author Share Posted May 21, 2018 (edited) 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 May 21, 2018 by shaba123 Quote Link to comment Share on other sites More sharing options...
shaba123 Posted May 21, 2018 Author Share Posted May 21, 2018 (edited) 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 May 21, 2018 by shaba123 Quote Link to comment Share on other sites More sharing options...
shaba123 Posted May 22, 2018 Author Share Posted May 22, 2018 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. Quote Link to comment Share on other sites More sharing options...
d0zza Posted May 22, 2018 Share Posted May 22, 2018 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). 1 Quote Link to comment Share on other sites More sharing options...
shaba123 Posted May 22, 2018 Author Share Posted May 22, 2018 Thank you d0zza ill look into that now Quote Link to comment Share on other sites More sharing options...
shaba123 Posted May 22, 2018 Author Share Posted May 22, 2018 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); } Quote Link to comment Share on other sites More sharing options...
d0zza Posted May 22, 2018 Share Posted May 22, 2018 (edited) 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 May 22, 2018 by d0zza Quote Link to comment Share on other sites More sharing options...
shaba123 Posted May 22, 2018 Author Share Posted May 22, 2018 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 Quote Link to comment Share on other sites More sharing options...
d0zza Posted May 22, 2018 Share Posted May 22, 2018 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. Quote Link to comment Share on other sites More sharing options...
shaba123 Posted May 22, 2018 Author Share Posted May 22, 2018 Yeah i mean its useless to ME not everyone , i know i cant use it properly. Okay thanks Quote Link to comment Share on other sites More sharing options...