Experience Tracker



  • Hello. I'm a new user here, upon looking over the API, I couldn't find something that can easily calculate different types of Experiences, such as Experience Hour, Experience Gained etc. For that, I created this little helpful snippet that gives you the ability to swiftly add any method you'd like, without having to manually type each skill down, and do the calculations.

    With this, the user is able to create:

    • Experience An Hour
    • Experience Gained
    • Experience To Next Level
    • Percentage To Next Level
    • Gained Levels

    To use it, simply create a class called Experience and copy paste the code below:

    /*
     * Developed By Asta on 05/02/19 23:35.
     * Last Modified 06/02/19 00:18.
     * Copyright (c) 2019. All rights reserved.
     */
    
    import org.rspeer.runetek.api.component.tab.Skill;
    import org.rspeer.runetek.api.component.tab.Skills;
    
    public class Experience {
        public final String xpHour(Skill skill, double startXp, long upTime) {
            double gainedXp = Skills.getExperience(skill) - startXp;
            return String.format("%.1f", (gainedXp * 3600000 / upTime) / 1000) + "K";
        }
    
        public final String xpToLvl(Skill skill) {
            return String.format("%.1f", ((double) Skills.getExperienceToNextLevel(skill) / 1000)) + "K";
        }
    
        public final String gainedXp(Skill skill, double startXp) {
            return String.format("%.1f", ((double) Skills.getExperience(skill) - startXp) / 1000) + "K";
        }
    
        public final int gainedLvl (Skill skill, int startLvl) {
            int currentSkillLevel = Skills.getLevel(skill);
            return currentSkillLevel - startLvl;
        }
    
        public final String percentToLvl(Skill skill) {
        
                long currentXp = Skills.getExperience(skill);
        
                int currentSkillLvl = Skills.getLevel(skill);
        
                long xpNextLvl = Skills.getExperienceAt(currentSkillLvl);
        
                long xpAtLvl = Skills.getExperienceAt(currentSkillLvl + 1);
        
                return (((xpNextLvl - currentXp) * 100) / (xpNextLvl - xpAtLvl)) + "% / 100%";
        
            }
    }
    

    The startXp & startLvl parameters, are for the variables that are initialized at onStart() as such:

    @Override
        public void onStart() {
            startTime = System.currentTimeMillis();
            startXp = Skills.getExperience(Skill.STRENGTH);
            startLvl = Skills.getLevel(Skill.STRENGTH);
        }
    

    To use the Experience class, we simply call it as such:

    Experience experience = new Experience();
    

    We can then use it as follows inside our paint:

            final long upTime = System.currentTimeMillis() - startTime;
    
            g.drawString("Current Level: " + Skills.getLevel(Skill.STRENGTH) + ("(" + experience.gainedLvl(Skill.STRENGTH,
            startLvl) + ")"), 5, 280);
            g.drawString("XP Gained: " + experience.gainedXp(Skill.STRENGTH, startXp), 5, 295);
            g.drawString("XP To Level: " + experience.xpToLvl(Skill.STRENGTH), 5, 310);
            g.drawString("XP/HR: " + experience.xpHour(Skill.STRENGTH, startXp, upTime), 5, 325);
            g.drawString("% To Level: " + experience.percentToLvl(Skill.STRENGTH), 5, 340);
    

    Enjoy 🙂



  • Awesome, Thank you!



  • Didn't look far enough just a few posts down lol

    https://forums.rspeer.org/topic/338/skill-tracking-snippet

    But more welcome


 

69
Online

8.6k
Users

905
Topics

11.7k
Posts