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
  • Where to put SkillTracker.start()? Checking to make sure account is logged in.


    Doxial

    Recommended Posts

    I'm trying to display how much xp is gained, my current code DOES work:
     

    public class Main extends AbstractScript{
        //Creating timer object
        Timer timer = new Timer();
        boolean skillTrackerStarted = false;
    
        @Override
        public void onStart() {
            timer.start();
            if(Players.getLocal().isOnScreen()) {
                SkillTracker.start();
                skillTrackerStarted = true;
            }
        }
    
        @Override
        public int onLoop() {
            //If statements checks if player is logged in
            if(skillTrackerStarted == false) {
                Logger.log("Sleeping until logged in");
                Sleep.sleep(10000);
                SkillTracker.start();
                skillTrackerStarted = true;
            } else {
                if (Inventory.isFull()) {
                    Inventory.dropAll("Logs");
                } else {
                    GameObject tree = GameObjects.closest("Tree");
                    if (tree != null) {
                        tree.interact("Chop down");
                        Sleep.sleep(500, 2500);
                        Sleep.sleepUntil(() -> !Players.getLocal().isAnimating(), 15000);
                    }
                }
                return 5000;
            }
            return 5000;
        }
    
        @Override
        public void onPaint(Graphics graphics) {
            try {
                Drawn(graphics);
            } catch(Exception e) {
                e.printStackTrace();;
            }
        }
    
        public void Drawn(Graphics graphics) {
            graphics.drawString("Experience Gained: " +  (SkillTracker.getGainedExperience(Skill.WOODCUTTING)), 20, 30);
            graphics.drawString("Time Elapsed: " +  timer.formatTime(), 20, 50);
        }
    
        @Override
        public void onExit() {
            Logger.log("Stopping");
        }
    }

     

    This was the solution I was able to come up with. Initially, I put SkillTracker.start() in the onStart method, but usually I wasn't logged in so it couldn't start. Then I tried putting Sleep.sleepUntil(() -> Client.isLoggedIn()); in onStart() however this would also pause the Login Solver. So I was wondering what is a more elegant way I can wait until I've logged in to then start my code?

    Link to comment
    Share on other sites

    public class Main extends AbstractScript {
        //Creating timer object
        Timer timer = new Timer();
        boolean skillTrackerStarted = false;
    
        @Override
        public void onStart() {
            timer.start();
    
           SkillTracker.start();
    
        }
    
        @Override
        public int onLoop() {
            while (!Client.isLoggedIn()){
                Logger.log("Waiting for login...");
                Sleep.sleep(1000);
            }
           if(!skillTrackerStarted){
                SkillTracker.start(Skill.WOODCUTTING);
                skillTrackerStarted = true;
            }
    
    
                if (Inventory.isFull()) {
                    Inventory.dropAll("Logs");
                } else {
                    GameObject tree = GameObjects.closest("Tree");
                    if (tree != null) {
                        tree.interact("Chop down");
                        Sleep.sleep(500, 2500);
                        Sleep.sleepUntil(() -> !Players.getLocal().isAnimating(), 15000);
                    }
                }
                return 5000;
    
        }
    
    
    
        @Override
        public void onPaint(Graphics graphics) {
            try {
                Drawn(graphics);
            } catch(Exception e) {
                e.printStackTrace();;
            }
        }
    
        public void Drawn(Graphics graphics) {
            graphics.drawString("Experience Gained: " +  (SkillTracker.getGainedExperience(Skill.WOODCUTTING)), 20, 30);
            graphics.drawString("Time Elapsed: " +  timer.formatTime(), 20, 50);
        }
    
        @Override
        public void onExit() {
            Logger.log("Stopping");
        }
    }
    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.