Jump to content

Question


mark jacobs

Recommended Posts

For this simple cooking script. When the bot clicks uses the salmon on the fire and then the cook all screen comes up, it will click the cook all widget, but sometimes it will try and use another fish on the fire after its already started cooking? why is that? I tried everything but still does this. any help or suggestions? Here is the script. I ended up putting random sleep delays as it helps it not do it as often, but still does. :(

 

 public void cookALL() throws InterruptedException {
        script.currentState = Status.Cooking;
        RS2Object fire = script.getObjects().closest("Fire");
        if (fire != null && !script.myPlayer().isAnimating()) {
            script.inventory.getItem("Raw salmon").interact("Use");
            sleep(random(544, 747));
            if (fire.interact("Use")) {
                sleep(random(555, 643));
                RS2Widget cookiconbutton = script.getWidgets().get(270, 14);
                cookiconbutton.interact();
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return !script.inventory.contains("Raw salmon") || script.widgets.isVisible(233) || script.getDialogues().isPendingContinuation();
                    }
                }.sleep();
            }
        }
    }

 

Link to comment
Share on other sites

18 hours ago, Czar said:

It's best to increase the delay to 20 seconds or so, or make a small int timer; and do timer+=8; every time an animation is detected, and at the top of onLoop make it s

if (timer > 0) {

return 1000;

}

really simple but effective :D it carried me in my early days of scripting :doge: 

 

Get your code up bby not your funny up
 

Sleep.until(()-> !script.inventory.contains("Raw salmon") || script.widgets.isVisible(233) || script.getDialogues().isPendingContinuation(), ()-> myPlayer().isAnimating(), 3_000);


Sleep.class
 


import java.util.concurrent.TimeUnit;
import java.util.function.BooleanSupplier;

public class Sleep {

    private static final int DEFAULT_POLLING = 600;
    private static final int DEFAULT_CYCLE_LIMIT = 100;

    public static void sleep(int time) {
        try {
            TimeUnit.MILLISECONDS.sleep(time);
        } catch (InterruptedException e) {
            // I don't wanna deal with Interrupted Exception handling everywhere
            // but I need it to reset the execution when it happens
            throw new IndexOutOfBoundsException("Sleep Interrupted*");
        }
    }

    public static boolean until(BooleanSupplier condition, int timeout) {
        return until(condition, ()-> false, timeout, DEFAULT_POLLING);
    }

    public static boolean until(BooleanSupplier condition, int timeout, int polling) {
        return until(condition, ()-> false, timeout, polling);
    }

    public static boolean until(BooleanSupplier condition, BooleanSupplier resetCondition, int timeout) {
        return until(condition, resetCondition, timeout, DEFAULT_POLLING, DEFAULT_CYCLE_LIMIT);
    }

    public static boolean until(BooleanSupplier condition, BooleanSupplier resetCondition, int timeout, int polling) {
        return until(condition, resetCondition, timeout, polling, DEFAULT_CYCLE_LIMIT);
    }

    public static boolean until(BooleanSupplier condition, BooleanSupplier resetCondition, int timeout, int polling, int cycleLimit) {
        try {
            int resetCounter = 0;
            long startTime = System.currentTimeMillis();

            while ((System.currentTimeMillis() - startTime) < timeout && !condition.getAsBoolean()) {
                if (resetCounter >= cycleLimit) {
                    break;
                } else if (resetCondition.getAsBoolean()) {
                    startTime = System.currentTimeMillis();
                    resetCounter ++;
                }

                Sleep.sleep(polling);
            }

            return condition.getAsBoolean();
        } catch (NullPointerException e) {
            e.printStackTrace();
        }

        return false;
    }

}

 

Link to comment
Share on other sites

5 hours ago, Gunman said:

Get your code up bby not your funny up
 

Sleep.until(()-> !script.inventory.contains("Raw salmon") || script.widgets.isVisible(233) || script.getDialogues().isPendingContinuation(), ()-> myPlayer().isAnimating(), 3_000);


Sleep.class
 


import java.util.concurrent.TimeUnit;
import java.util.function.BooleanSupplier;

public class Sleep {

    private static final int DEFAULT_POLLING = 600;
    private static final int DEFAULT_CYCLE_LIMIT = 100;

    public static void sleep(int time) {
        try {
            TimeUnit.MILLISECONDS.sleep(time);
        } catch (InterruptedException e) {
            // I don't wanna deal with Interrupted Exception handling everywhere
            // but I need it to reset the execution when it happens
            throw new IndexOutOfBoundsException("Sleep Interrupted*");
        }
    }

    public static boolean until(BooleanSupplier condition, int timeout) {
        return until(condition, ()-> false, timeout, DEFAULT_POLLING);
    }

    public static boolean until(BooleanSupplier condition, int timeout, int polling) {
        return until(condition, ()-> false, timeout, polling);
    }

    public static boolean until(BooleanSupplier condition, BooleanSupplier resetCondition, int timeout) {
        return until(condition, resetCondition, timeout, DEFAULT_POLLING, DEFAULT_CYCLE_LIMIT);
    }

    public static boolean until(BooleanSupplier condition, BooleanSupplier resetCondition, int timeout, int polling) {
        return until(condition, resetCondition, timeout, polling, DEFAULT_CYCLE_LIMIT);
    }

    public static boolean until(BooleanSupplier condition, BooleanSupplier resetCondition, int timeout, int polling, int cycleLimit) {
        try {
            int resetCounter = 0;
            long startTime = System.currentTimeMillis();

            while ((System.currentTimeMillis() - startTime) < timeout && !condition.getAsBoolean()) {
                if (resetCounter >= cycleLimit) {
                    break;
                } else if (resetCondition.getAsBoolean()) {
                    startTime = System.currentTimeMillis();
                    resetCounter ++;
                }

                Sleep.sleep(polling);
            }

            return condition.getAsBoolean();
        } catch (NullPointerException e) {
            e.printStackTrace();
        }

        return false;
    }

}

 

Ty sir seems to work perfect now! Should i be using this sleep class instead of conditional sleep?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...