mark jacobs Posted May 3 Share Posted May 3 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(); } } } Quote Link to comment Share on other sites More sharing options...
Czar Posted May 4 Share Posted May 4 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 it carried me in my early days of scripting Quote Link to comment Share on other sites More sharing options...
Gunman Posted May 5 Share Posted May 5 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 it carried me in my early days of scripting 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; } } Quote Link to comment Share on other sites More sharing options...
mark jacobs Posted May 5 Author Share Posted May 5 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? Quote Link to comment Share on other sites More sharing options...
Gunman Posted May 6 Share Posted May 6 13 hours ago, mark jacobs said: Ty sir seems to work perfect now! Should i be using this sleep class instead of conditional sleep? It's another take on the conditional sleep class that makes it a one liner with lambdas and a reset condition. Imo I'd use the Sleep class because of the reset condition option Quote Link to comment Share on other sites More sharing options...