kingbutton Posted August 17, 2017 Share Posted August 17, 2017 When I run the code. It would cook the fish, and then click on the fish besides it in the inventory. Cook another fish, then it would stop, and repeat itself. Cooks 3 fishes at a time before it loops back up. How do i make it so it just chills after cooks all and goes through the full inventory? public void goCook() { RS2Object fire = objects.closest("Fire"); RS2Widget optionMenu = getWidgets().get(307, 2); if (inventory.interactWithNameThatContains("Use", "Raw")) { if (optionMenu != null) { if (optionMenu.interact("Cook All")) { new ConditionalSleep(random(3000, 4500)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } else { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { if (fire.interact("Use")) { new ConditionalSleep(random(4000, 5000)) { @Override public boolean condition() throws InterruptedException { return optionMenu != null; } }.sleep(); } } } } } Quote Link to comment Share on other sites More sharing options...
Charlotte Posted August 17, 2017 Share Posted August 17, 2017 new ConditionalSleep(random(4000, 5000)) This is the time taken to cook at least 3 fish. Quote Link to comment Share on other sites More sharing options...
Jake Slang Posted August 17, 2017 Share Posted August 17, 2017 (edited) You need a conditional sleep. Now you're just sleeping for 4-5 seconds (which your script uses to cook 3 fishes before looping again). So what you want is: Sleep.sleepUntil(() -> condition, timeout); Now it will sleep until the condition (is true) or the timeout is met. The condition could be till there are no raw fishes left in your inventory. I would give the timeout some absurd number so you'll pretty much only stop cooking when the condition evaluates to true. In order to use this static sleepUntil() method, you should add this snippet under your main class: https://hastebin.com/azusobiyur.java Also check out: Edited August 17, 2017 by Jake Slang Quote Link to comment Share on other sites More sharing options...
d0zza Posted August 17, 2017 Share Posted August 17, 2017 The problem is the fact that when cooking your player constantly switches from animating to not animating. If you switch on 'my player debug' in settings you'll see this happen. An easy way to get around this is to keep track of the last time your player animated. Check out this thread: Quote Link to comment Share on other sites More sharing options...
kingbutton Posted August 20, 2017 Author Share Posted August 20, 2017 On 8/17/2017 at 4:01 AM, Jake Slang said: You need a conditional sleep. Now you're just sleeping for 4-5 seconds (which your script uses to cook 3 fishes before looping again). So what you want is: Sleep.sleepUntil(() -> condition, timeout); Now it will sleep until the condition (is true) or the timeout is met. The condition could be till there are no raw fishes left in your inventory. I would give the timeout some absurd number so you'll pretty much only stop cooking when the condition evaluates to true. In order to use this static sleepUntil() method, you should add this snippet under your main class: https://hastebin.com/azusobiyur.java Also check out: I'm not too familiar with BooleanSuppliers... Sleep.sleepUntil(!inventory.contains("raw"), 5000); So I can't use a boolean, I need to use a booleansupplier. Can you explain how to properly use this snippet? I did add it under my MainClass, so that isn't the issue. Quote Link to comment Share on other sites More sharing options...
Jake Slang Posted August 20, 2017 Share Posted August 20, 2017 (edited) On 20-8-2017 at 8:20 AM, kingbutton said: I'm not too familiar with BooleanSuppliers... Sleep.sleepUntil(!inventory.contains("raw"), 5000); So I can't use a boolean, I need to use a booleansupplier. Can you explain how to properly use this snippet? I did add it under my MainClass, so that isn't the issue. Something like this: Sleep.sleepUntil(() -> !getInventory().contains("rawFoodName"), 120000); So now your player will sleep until your inventory doesn't contain the given raw food (first parameter), or until the timeout is hit (which is set to 2 minutes now). You have to think about the timeout. I've set it to 2 minutes, because the first parameter will most likely evaluate to false, but you don't want the second parameter to evaluate to true after like 3 seconds, which will loop your script again. This snippet is made because it is shorter and self-explanatory in the way you read it: Let your script sleep until the first given parameter is truthy (thus continue running your script), or until the timeout is hit (thus continue running your script). Timeout is in milliseconds btw. Edited August 22, 2017 by Jake Slang Quote Link to comment Share on other sites More sharing options...
kingbutton Posted August 21, 2017 Author Share Posted August 21, 2017 public void goCook() { RS2Object fire = objects.closest("Fire"); RS2Widget optionMenu = getWidgets().get(307, 2); if (inventory.interactWithNameThatContains("Use", "Raw")) { if (optionMenu != null) { if (optionMenu.interact("Cook All")) { new ConditionalSleep(random(3000, 4500)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } else { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { if (fire.interact("Use")) { Sleep.sleepUntil(() -> !getInventory().contains("rawFoodName", 120000)); } } } import org.osbot.rs07.utility.ConditionalSleep; import java.util.function.BooleanSupplier; public final class Sleep extends ConditionalSleep { private final BooleanSupplier condition; public Sleep(final BooleanSupplier condition, final int timeout) { super(timeout); this.condition = condition; } @Override public final boolean condition() throws InterruptedException { return condition.getAsBoolean(); } public static boolean sleepUntil(final BooleanSupplier condition, final int timeout) { return new Sleep(condition, timeout).sleep(); } } Okay so even when I paste exactly what you have, btw you for a parenthesis, It's still giving me an error. Quote Link to comment Share on other sites More sharing options...
kingbutton Posted August 22, 2017 Author Share Posted August 22, 2017 I figured out how to make the code work without the error, but I'm still having the same issue where it's trying to click on a fish in my inventory, clicks on a cooked fish, and then it doesn't sleep until the inventory is finished. Sleep.sleepUntil(() -> !getInventory().contains("raw"), 5000); Even when I change the 5000 to something insane, still does the same thing. Quote Link to comment Share on other sites More sharing options...
d0zza Posted August 22, 2017 Share Posted August 22, 2017 20 minutes ago, kingbutton said: I figured out how to make the code work without the error, but I'm still having the same issue where it's trying to click on a fish in my inventory, clicks on a cooked fish, and then it doesn't sleep until the inventory is finished. Sleep.sleepUntil(() -> !getInventory().contains("raw"), 5000); Even when I change the 5000 to something insane, still does the same thing. On 17/08/2017 at 9:14 PM, d0zza said: The problem is the fact that when cooking your player constantly switches from animating to not animating. If you switch on 'my player debug' in settings you'll see this happen. An easy way to get around this is to keep track of the last time your player animated. Check out this thread: Quote Link to comment Share on other sites More sharing options...
kingbutton Posted August 22, 2017 Author Share Posted August 22, 2017 2 hours ago, d0zza said: Okay so I tried this also. I'm probably implementing it wrong in the code, cause they way I have it set up. Seems a bit confusing and I feel like I have some things that are in the wrong spots. Can you see what's wrong with it then, cause it's still doing the same thing. public void goCook() { RS2Object fire = objects.closest("Fire"); RS2Widget optionMenu = getWidgets().get(307, 2); if (inventory.interactWithNameThatContains("Use", "Raw")) { if (optionMenu != null) { if (optionMenu.interact("Cook All")) { new ConditionalSleep(random(3000, 4500)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } else { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { long lastAnimation = 0; if (myPlayer().isAnimating()) { lastAnimation = System.currentTimeMillis(); } else if (System.currentTimeMillis() > (lastAnimation + 4500)) { if (fire.interact("Use")) { Sleep.sleepUntil(() -> !getInventory().contains("raw"), 5000); } } } } } } Quote Link to comment Share on other sites More sharing options...
Jake Slang Posted August 22, 2017 Share Posted August 22, 2017 (edited) Check my previous post. I've updated the syntax, it should work now. I made a mistake, I think I just woke up around that time, my bad.. Also,, that rawFoodName (between quotes) was just a parameter/placeholder, you should pass in the full name of the raw fish: Sleep.sleepUntil(() -> !getInventory().contains("Raw tuna"), 120000); Oh, and make sure the timeout is around 2 minutes, or else it'll try cooking again after 5 seconds. If you cook a variety of food you could also do: Sleep.sleepUntil(() -> !getInventory().contains("Raw tuna") && !getInventory().contains("Raw lobster"), 120000); Edited August 22, 2017 by Jake Slang Quote Link to comment Share on other sites More sharing options...
d0zza Posted August 22, 2017 Share Posted August 22, 2017 (edited) 6 hours ago, kingbutton said: Okay so I tried this also. I'm probably implementing it wrong in the code, cause they way I have it set up. Seems a bit confusing and I feel like I have some things that are in the wrong spots. Can you see what's wrong with it then, cause it's still doing the same thing. public void goCook() { RS2Object fire = objects.closest("Fire"); RS2Widget optionMenu = getWidgets().get(307, 2); if (inventory.interactWithNameThatContains("Use", "Raw")) { if (optionMenu != null) { if (optionMenu.interact("Cook All")) { new ConditionalSleep(random(3000, 4500)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } else { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { long lastAnimation = 0; if (myPlayer().isAnimating()) { lastAnimation = System.currentTimeMillis(); } else if (System.currentTimeMillis() > (lastAnimation + 4500)) { if (fire.interact("Use")) { Sleep.sleepUntil(() -> !getInventory().contains("raw"), 5000); } } } } } } Your logic is wrong. First off you want lastAnimation to be a global variable since you want to be able to access it in multiple situations. The logic you want to follow when cooking is: Am I animating? if not, has it been a few seconds since I last animated? If yes use fish on fire. if yes, update lastAnimation and keep cooking. So basically you want to have this check before you call goCook(); Edited August 22, 2017 by d0zza 1 Quote Link to comment Share on other sites More sharing options...
Abysm Posted August 22, 2017 Share Posted August 22, 2017 Also this guy has his conditional sleep to check if he has item named "raw" in inventory... You need to use filter Quote Link to comment Share on other sites More sharing options...
kingbutton Posted August 23, 2017 Author Share Posted August 23, 2017 16 hours ago, Abysm said: Also this guy has his conditional sleep to check if he has item named "raw" in inventory... You need to use filter How do you use filters? Never had to use them before for my other scripts Quote Link to comment Share on other sites More sharing options...
kingbutton Posted August 24, 2017 Author Share Posted August 24, 2017 On 8/22/2017 at 5:17 AM, d0zza said: Your logic is wrong. First off you want lastAnimation to be a global variable since you want to be able to access it in multiple situations. The logic you want to follow when cooking is: Am I animating? if not, has it been a few seconds since I last animated? If yes use fish on fire. if yes, update lastAnimation and keep cooking. So basically you want to have this check before you call goCook(); Okay so I got it to chill after it does "Cook all", and technically my code is working smoothly, but there's one thing that is unhuman like and needs to be address. When it tries to interact with the fire, it tries to click several times, kind of like the thing issue I had before. It doesn't bug out or anything, but it bothers me that does it, any solutions? I tried working with the sleep, but it's not working. public class Main extends Script { long lastAnimation = 0; @Override public int onLoop() throws InterruptedException { if (invCheck()) { if (fireCheck()) { log("Go cook"); if (myPlayer().isAnimating()) { lastAnimation = System.currentTimeMillis(); } else if (System.currentTimeMillis() > (lastAnimation + 12000)) { goCook(); } } else { log("Make fire"); makeFire(); } } else { } return 50; } public void goCook() { RS2Object fire = objects.closest("Fire"); RS2Widget optionMenu = getWidgets().get(307, 2); if (inventory.interactWithNameThatContains("Use", "Raw")) { if (optionMenu != null) { if (optionMenu.interact("Cook All")) { new ConditionalSleep(random(3000, 4500)) { @Override public boolean condition() throws InterruptedException { return myPlayer().isAnimating(); } }.sleep(); } } else { if (!myPlayer().isAnimating() && !myPlayer().isMoving()) { if (fire.interact("Use")) { Sleep.sleepUntil(() -> !getInventory().contains("raw"), 12000); } } } } } Quote Link to comment Share on other sites More sharing options...