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
  • How does sleepUntil work?


    Binarybunny

    Recommended Posts

    so sleepUntil.. let's say I ahve this

    //If the player is fishing.
            if (getLocalPlayer().getAnimation() == 621)
            {
                //sleep until te player is idle or 2000
                sleepUntil(() -> getLocalPlayer().getAnimation() == -1, 2000);
            }
    

    If 2 seconds pass will it run the if

    (getLocalPlayer().getAnimation() == 621)

    again? Or just keep moving down to the next line of code?

    Link to comment
    Share on other sites

    //If the player is fishing.
            if (getLocalPlayer().getAnimation() == 621)
            {
                //sleep until te player is idle or 2000
                sleepUntil(() -> getLocalPlayer().getAnimation() == -1, 2000);
            }
    

    Going from ur code,

     

    this will make the bot sleep untill ur character is idle or if 2 seconds passed

     

    also a good thing to add would be getDialogues().inDialogue() (for lv ups) but thats more if u do a longer sleep.

     

    u can also sleepWhile the player is doing a certain animation

    And yes this will repeat untill ur players animation isnt 621.

    Link to comment
    Share on other sites

    If 2 seconds pass will it run the if

    (getLocalPlayer().getAnimation() == 621)

    again? Or just keep moving down to the next line of code?

    It'll keep moving to the next line of code.

    Link to comment
    Share on other sites

    Exactly what Pyth said.

     

    It'll keep looping through the sleepUntil until the return condition is true or the timeout has elapsed. Whichever comes first. Then it will move on to the next line of code regardless.

     

    I believe it loops every 20ms or so.

    Link to comment
    Share on other sites

    Maybe this helps a bit, this is what it COULD BE DOING code wise

    if (getLocalPlayer().getAnimation() == 621) {
    	sleepUntil(() -> getLocalPlayer().getAnimation() == -1, 2000);
    }
    
    private boolean sleepUntil(Condition condition, long timeout) {
    	long start = System.currentTimeMillis();
    	while((System.currentTimeMillis() - start) < timeout) {
    		if (condition.verify()) {
    			return true;
    		}
    	}
    	return false;
    }
    
    Link to comment
    Share on other sites

     

    Maybe this helps a bit, this is what it COULD BE DOING code wise

    if (getLocalPlayer().getAnimation() == 621) {
    	sleepUntil(() -> getLocalPlayer().getAnimation() == -1, 2000);
    }
    
    private boolean sleepUntil(Condition condition, long timeout) {
    	long start = System.currentTimeMillis();
    	while((System.currentTimeMillis() - start) < timeout) {
    		if (condition.verify()) {
    			return true;
    		}
    	}
    	return false;
    }
    
    
    
    if (getLocalPlayer().getAnimation() == 621) {
    	sleepUntil(() -> getLocalPlayer().getAnimation() == -1, 2000);
    }
    
    private boolean sleepUntil(Condition condition, long timeout) {
    	long start = System.currentTimeMillis();
    	while((System.currentTimeMillis() - start) < timeout) {
    		if (condition.verify()) {
    			return true;
    		}
                    MethodProvider.sleep(25);<-- u 4got this!
    	}
    	return false;
    }
    
    
    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • 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.