Item Count Notifier

IntermediateUtility

Notifies you when you have a certain number of items. Useful for tracking supplies or resources.

12 min read

What It Does

Notifies you when you have a certain number of items. Useful for tracking supplies or resources.

Source Code

java
1package com.example;
2
3import net.runelite.api.Client;
4import net.runelite.api.ItemContainer;
5import net.runelite.api.events.GameTick;
6import net.runelite.client.eventbus.Subscribe;
7import net.runelite.client.plugins.Plugin;
8import net.runelite.client.plugins.PluginDescriptor;
9import javax.inject.Inject;
10
11@PluginDescriptor(
12    name = "Item Count Notifier",
13    description = "Alerts on item count"
14)
15public class ItemCountNotifierPlugin extends Plugin {
16    @Inject
17    private Client client;
18
19    private final int targetItemId = 385; // Shark
20    private final int threshold = 10;
21    private boolean notified = false;
22
23    @Subscribe
24    public void onGameTick(GameTick event) {
25        ItemContainer inventory = client.getItemContainer(InventoryID.INVENTORY);
26        if (inventory == null) {
27            return;
28        }
29
30        int count = inventory.count(targetItemId);
31        if (count <= threshold && !notified) {
32            client.addChatMessage(
33                net.runelite.api.ChatMessageType.GAMEMESSAGE,
34                "",
35                "Warning: You have " + count + " items left!",
36                null
37            );
38            notified = true;
39        } else if (count > threshold) {
40            notified = false;
41        }
42    }
43}

Code Annotations

Line 18

Item ID to track

Line 19

Alert threshold

Line 20

Prevent spam notifications

Line 28

Count items in inventory

API Classes Used

Key Concepts

  • Item ID to track
  • Alert threshold
  • Prevent spam notifications
  • Count items in inventory

Next Steps

  • Learn about item counting
  • Add configurable item and threshold
  • Add multiple item tracking