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
  • Try asking for help in the chatbox
  • How can I add a random sleep time to a script?


    mariotcc
     Share

    Recommended Posts

    Hi guys I am currently workin on a simple woodcutting script, so far it loops well, managed to get 1-23 woodcutting with no problem at all.

    To expand on this script and make it better, I would like to implement a random sleep time after cutting each log, as I feel it would make sense and appear more realistic. I will show my code with my mistake as it may show you guys where I am trying to add the sleep function logically (may be wrong place but i think it will help understand my thought process)

    package main;
    
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.wrappers.interactive.GameObject;
    
    @ScriptManifest(author = "Mario", name = "firstScript", version = 2, description = "First Demo!", category = Category.MONEYMAKING)
    
    public class main extends AbstractScript {
    
        @Override
        public void onStart() {
    
            log("Script has now Started!");
            log("Enjoy My Demo Script!");
    
        }
    
        @Override
        public int onLoop() {
            Area cuttingArea = new Area(3138,3257,3157,3239);
            if (!getLocalPlayer().isAnimating()) {
                if(cuttingArea.contains(getLocalPlayer()));
                    else{
                        getWalking().walk(cuttingArea.getRandomTile());
                }
                if(getInventory().isFull()){
                    getInventory().dropAllExcept("Small fishing net");
                } else{
                    GameObject tree = getGameObjects().closest("Tree");
                    if (tree != null){
                        tree.interact("Chop Down");
                        log("Cutting Tree");
                    }
                    if(tree.interact("Chop Down")){
                        int countLog = getInventory().count("logs");
                        sleepUntil(() -> getInventory().count("logs") > countLog, 10000);
                        sleep((int) (Math.random() * 7002));
                    }
                }
    
            }
    
    
            return 1500;
    
        }
    
        @Override
        public void onExit() {
    
            log("The Script Has Ended!");
    
        }
    
    }

    Thank you in advance guys! any help will be greatly appreciated!

    Link to comment
    Share on other sites

    Quote
    2 minutes ago, Infidel said:
    
    sleep(1000);
    
    sleep(Calculations.random(1000,1300);
    
    sleepUntil(() -> !getLocalPlayer().isAnimating(), 4000);
    
    sleepWhile(() ->  getLocalPlayer().isAnimating(), 4000);

     

     

    thank you mate! appreciate your time and help! I am sure this will help other noobs like myself.

    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
     Share

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