Bank Value Calculator

IntermediateData

Calculates the total value of items in your bank. Demonstrates item iteration and value calculation.

18 min read

What It Does

Calculates the total value of items in your bank. Demonstrates item iteration and value calculation.

Source Code

java
1package com.example;
2
3import net.runelite.api.Client;
4import net.runelite.api.ItemContainer;
5import net.runelite.api.Item;
6import net.runelite.client.plugins.Plugin;
7import net.runelite.client.plugins.PluginDescriptor;
8import javax.inject.Inject;
9
10@PluginDescriptor(
11    name = "Bank Value Calculator",
12    description = "Calculates bank value"
13)
14public class BankValuePlugin extends Plugin {
15    @Inject
16    private Client client;
17
18    @Subscribe
19    public void onGameTick(GameTick event) {
20        ItemContainer bank = client.getItemContainer(InventoryID.BANK);
21        if (bank == null) {
22            return;
23        }
24
25        long totalValue = 0;
26        for (Item item : bank.getItems()) {
27            if (item.getId() != -1) {
28                int itemId = item.getId();
29                int quantity = item.getQuantity();
30                // Get item price (would need ItemManager)
31                // long price = itemManager.getItemPrice(itemId);
32                // totalValue += price * quantity;
33            }
34        }
35
36        System.out.println("Bank value: " + totalValue + " gp");
37    }
38}

Code Annotations

Line 20

Get bank container

Line 25

Iterate through all bank items

Line 29

Calculate total value (needs ItemManager)

API Classes Used

Key Concepts

  • Get bank container
  • Iterate through all bank items
  • Calculate total value (needs ItemManager)

Next Steps

  • Learn about ItemManager API
  • Add overlay to display value
  • Cache prices for performance