XP Tracker

IntermediateData

Tracks and displays experience points gained. Shows how to monitor stat changes and calculate XP gains over time.

12 min read

What It Does

Tracks and displays experience points gained. Shows how to monitor stat changes and calculate XP gains over time.

Source Code

java
1package com.example;
2
3import net.runelite.api.Client;
4import net.runelite.api.Skill;
5import net.runelite.api.events.StatChanged;
6import net.runelite.client.eventbus.Subscribe;
7import net.runelite.client.plugins.Plugin;
8import net.runelite.client.plugins.PluginDescriptor;
9import java.util.HashMap;
10import java.util.Map;
11
12@PluginDescriptor(
13    name = "XP Tracker",
14    description = "Tracks experience points gained"
15)
16public class XPTrackerPlugin extends Plugin {
17    @Inject
18    private Client client;
19
20    private Map<Skill, Integer> lastXP = new HashMap<>();
21
22    @Subscribe
23    public void onStatChanged(StatChanged event) {
24        Skill skill = event.getSkill();
25        int currentXP = client.getSkillExperience(skill);
26        Integer previousXP = lastXP.get(skill);
27        
28        if (previousXP != null) {
29            int xpGained = currentXP - previousXP;
30            if (xpGained > 0) {
31                System.out.println(skill.getName() + " XP gained: " + xpGained);
32            }
33        }
34        
35        lastXP.put(skill, currentXP);
36    }
37}

Code Annotations

Line 18

Map to store last known XP for each skill

Line 22

Listen for StatChanged events when skills change

Line 25

Calculate XP gained by comparing current and previous values

API Classes Used

Key Concepts

  • Map to store last known XP for each skill
  • Listen for StatChanged events when skills change
  • Calculate XP gained by comparing current and previous values

Next Steps

  • Learn about Skill API
  • Add overlay to display XP rates
  • Track XP per hour