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
  • Paint throwing errors with Combat Level


    mcleod63

    Recommended Posts

    Hi, can anyone help me understand why my Paint is throwing errors?

    The error appears to be caused by Players.getLocal().getLevel() throwing errors until the login handler has finished. I say this because the logs show login handler starting, and then repetitive errors pointing to my codeline 143, and the errors stop as soon as the log shows that the login handler finished. I can show the log entries if that will help.

    This is line 143 in my code:

    g.drawString("Combat skill level: " + Players.getLocal().getLevel(), 10, 135);

    I recently returned to botting after taking a 1-2 year break, so I had to update my scripts for the deprecated items since I last played. That included changing getLocalPlayer().getLevel() to Players.getLocal().getLevel() but I don't see how that is the problem.

    Any help would be appreciated.

    Link to comment
    Share on other sites

    one solution could be null checking if youre logged in or if the local player is not null before painting the paint text and draw the text

    getlocalplayer to players.getlevel should not affect that

    in your onpaint method, something like this pseudocode

    if (!loggedin) {
    wait to load in
    }  else {
    drawstring()
    drawstring()
    drawrect()
    }

     

    Link to comment
    Share on other sites

    `Players.getLocal()` can return null, so you need to null check or catch the exception.

    int level = 0
    Player me = Players.getLocal()
    if (me != null) {
      level = me.getLevel()
    }
    g.drawString("Combat skill level: " + level, 10, 135);
    
    OR
    
    try {
      g.drawString("Combat skill level: " + Players.getLocal().getLevel(), 10, 135);
    } catch (Exception e) {
      Logger.log("Unable to get player level: " + e.getMessage())
    }
    Edited by hashbang
    Link to comment
    Share on other sites

    Oh no, I fell for the 'failed to do a null check"' thing. Thank you both for the responses. 

    Must remember null checks. Must remember null checks. Must remember null checks. 

    Link to comment
    Share on other sites

    Just a quick update. This one solved my issue. Thanks again for the helpful responses!

     
    Player player = Players.getLocal();
    
    if (player != null) {
        g.drawString("Combat Level: " + player.getLevel(), 10, 90);
    }
     
    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.