Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Skills.getRealLevel contains previous level in ExperienceEvent


    ink12345

    Recommended Posts

    I am writing a script and I want to perform certain actions (change attack styles or equip new gear) when hitting level thresholds.

    I have written an ExperienceListener and overridden the onLevelUp method, and am logging the skill along with the level that was reached

    class LevelTracker implements ExperienceListener {
    
    @Override
    public void onLevelUp(ExperienceEvent e) {
        log("Leveled up " + e.getSkill().toString() + " to " + Skills.getRealLevel(e.getSkill()));

    }

    }

    However Skills.getRealLevel() always seems to return the previous level rather than the new one.  For example, if I just hit 20 attack, it would log "Leveled up Attack to level 19".

    Is this intended? Should I just use Skills.getRealLevel() + 1 for this type of action?

     

    Link to comment
    Share on other sites

    1 hour ago, ink12345 said:

    I am writing a script and I want to perform certain actions (change attack styles or equip new gear) when hitting level thresholds.

    I have written an ExperienceListener and overridden the onLevelUp method, and am logging the skill along with the level that was reached

    class LevelTracker implements ExperienceListener {
    
    @Override
    public void onLevelUp(ExperienceEvent e) {
        log("Leveled up " + e.getSkill().toString() + " to " + Skills.getRealLevel(e.getSkill()));

    }

    }

    However Skills.getRealLevel() always seems to return the previous level rather than the new one.  For example, if I just hit 20 attack, it would log "Leveled up Attack to level 19".

    Is this intended? Should I just use Skills.getRealLevel() + 1 for this type of action?

     

    Did you start SkillTracker?

    SkillTracker.start(); // Starts tracking all skills
    SkillTracker.start(Skill skillA, Skill skillB,....); // Starts tracking defined Skills

     

    Link to comment
    Share on other sites

    It's possible it's intended, I'm not sure. But instead of doing Skills.getLevel(e.getSkill()) + 1 you should be doing Skills.getLevel(e.getSkill()) + e.getChange() in case you level up multiple levels at once. That's more common in quests, but just to be sure.

    Link to comment
    Share on other sites

    1 hour ago, Hashtag said:

    It's possible it's intended, I'm not sure. But instead of doing Skills.getLevel(e.getSkill()) + 1 you should be doing Skills.getLevel(e.getSkill()) + e.getChange() in case you level up multiple levels at once. That's more common in quests, but just to be sure.

    It's always a good idea to follow best practices, even when they may not seem necessary at first. 👍

    Edited by sloppybot
    Link to comment
    Share on other sites

    I am not sure what the skill tracker would help with in this situation, even after gaining multiple levels the log message was always the level that was leveled up from.

    I implemented it using getRealLevel() + getChange() and it's been working fine that way.  Thanks!

    Link to comment
    Share on other sites

    11 minutes ago, ink12345 said:

    I am not sure what the skill tracker would help with in this situation, even after gaining multiple levels the log message was always the level that was leveled up from.

    I implemented it using getRealLevel() + getChange() and it's been working fine that way.  Thanks!

    I apologize for the misunderstanding. I was reading the forums while waiting for my taxi to the airport, and I had only gotten 3.5 hours of sleep, which led to me completely misinterpreting the question. Glad you got the help you needed. :)

    Edited by sloppybot
    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.