Jump to content

Cooking bot, double click


kingbutton

Recommended Posts

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();
					}
				}

			}
		}

	}

 

Link to comment
Share on other sites

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 by Jake Slang
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Jake Slang
Link to comment
Share on other sites

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. 

sI9KtME.png

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

 

 

Link to comment
Share on other sites

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);
						}
					}

				}
			}

		}
	}

 

Link to comment
Share on other sites

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 by Jake Slang
Link to comment
Share on other sites

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 by d0zza
  • Like 1
Link to comment
Share on other sites

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);
					}
				}

			}
		}

	}

 

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