Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Help with cooking

Featured Replies

Hey, so I'm working on a project but for some reason can't get this working, any help would be appreciated

I know its bad rn, its incomplete

private void cook() {
        RS2Widget option = getWidgets().get(307, 2);
        if (!myPlayer().isAnimating()) {
            RS2Object fire = getObjects().closest(rs2Object -> rs2Object.getName().equals("Fire"));
            if (fire != null) {
                if (option == null) {
                    getInventory().interact("Use", currentFood);
                    fire.interact("Use");
                    if (option.isVisible()) {
                        option.interact("Cook All");
                    }
                }
            }
        }
    }

Heres my cooking function, It's doing everything until the interact for Cook All

It's a valiant attempt but I think you need to consider the structure a little. Since you're writing a script for a live game, you've got to consider factors such as latency fluctuation and misclicks - these factors mean lines of code which interact with the game cannot be 100% guaranteed successful. As a result, you have to write your script in a state based manner to account for this. Typically, I would suggest aiming for performing a single action per loop of your onLoop. Ofcourse me saying that is very subjective on the structure of the code you have in place at the moment, but for simple scripts where you drop everything in the onLoop, one action per loop seems fair enough. This means at no point should you chain actions that depend on one another - a classic example of this is:

getBank().open();
getBank().depositAll();

Instead, you want to make use of the continually looping nature of your onLoop and make the interactions conditional:

if (getBank().isOpen()) {
    getBank().depositAll();
} else {
    getBank().open();
}

I know it's a very simple example, but it illustrates the point - when the second example runs, the first onLoop loop will open the bank, and the second will deposit your items. The first one will attempt to do them in succession, and if the initial getBank()#open call fails, then you will potentially be left with a nasty error and/or unexpected behaviour from there on. As you can imagine, the more actions you chain in this manner, the worse this unpredictability will become.

Anyway, with that out the way, your code. Since cooking something is quite a complex task with alot of clicking on this and clicking on that in a particular order, it forms a really good problem for you to try and solve. I would highly recommend the use of ConditionalSleeps in your code to make it more efficient - these can be defined anonymously as follows:

new ConditionalSleep(5000) {
    @Override
    public boolean condition() {
        return myPlayer().isAnimating();
    }
}.sleep();

(Wrote that in the reply box, apologies if there are any typos/anything I missed - it's late!)

That code will create an anonymous instance of ConditionalSleep and in this case will sleep until either 5000 milliseconds elapse or your player is animating. ConditionalSleep#sleep() returns a boolean of whether or not the condition was met before the time expired, but we're not using that feature in this snippet.

Also, don't use child/grandchild widget ids! Instead, search for widgets containing text, or do something else which doesn't require arbitrary ints in your code which could change when the game is updated.

Hope that helped, I know I didn't answer you directly as there's nothing to be learned from spoonfed code! let me know if you need anything else!

-Apa (:

  • Author
10 minutes ago, Apaec said:

It's a valiant attempt but I think you need to consider the structure a little. Since you're writing a script for a live game, you've got to consider factors such as latency fluctuation and misclicks - these factors mean lines of code which interact with the game cannot be 100% guaranteed successful. As a result, you have to write your script in a state based manner to account for this. Typically, I would suggest aiming for performing a single action per loop of your onLoop. Ofcourse me saying that is very subjective on the structure of the code you have in place at the moment, but for simple scripts where you drop everything in the onLoop, one action per loop seems fair enough. This means at no point should you chain actions that depend on one another - a classic example of this is:


getBank().open();
getBank().depositAll();

Instead, you want to make use of the continually looping nature of your onLoop and make the interactions conditional:


if (getBank().isOpen()) {
    getBank().depositAll();
} else {
    getBank().open();
}

I know it's a very simple example, but it illustrates the point - when the second example runs, the first onLoop loop will open the bank, and the second will deposit your items. The first one will attempt to do them in succession, and if the initial getBank()#open call fails, then you will potentially be left with a nasty error and/or unexpected behaviour from there on. As you can imagine, the more actions you chain in this manner, the worse this unpredictability will become.

Anyway, with that out the way, your code. Since cooking something is quite a complex task with alot of clicking on this and clicking on that in a particular order, it forms a really good problem for you to try and solve. I would highly recommend the use of ConditionalSleeps in your code to make it more efficient - these can be defined anonymously as follows:


new ConditionalSleep(5000) {
    @Override
    public boolean condition() {
        return myPlayer().isAnimating();
    }
}.sleep();

(Wrote that in the reply box, apologies if there are any typos/anything I missed - it's late!)

That code will create an anonymous instance of ConditionalSleep and in this case will sleep until either 5000 milliseconds elapse or your player is animating. ConditionalSleep#sleep() returns a boolean of whether or not the condition was met before the time expired, but we're not using that feature in this snippet.

Also, don't use child/grandchild widget ids! Instead, search for widgets containing text, or do something else which doesn't require arbitrary ints in your code which could change when the game is updated.

Hope that helped, I know I didn't answer you directly as there's nothing to be learned from spoonfed code! let me know if you need anything else!

-Apa (:

Wow! Thanks a ton, I will definitely look into using ConditionalSleeps and making sure I don't just have actions one after the other. I appreciate the help!

RS2Widget nameWidget = s.getWidgets().getWidgetContainingText("My name is Visty");

if (nameWidget != null && nameWidget.isVisible()) {
                        nameWidget.interact("Hello Visty");
}

Here is an example of how the method can look like. Read Apaec's post, and compare it to the snippet I've created to have a good understanding.

Edited by Visty

  • Author
7 minutes ago, Visty said:

RS2Widget nameWidget = s.getWidgets().getWidgetContainingText("My name is Visty");

if (nameWidget != null && nameWidget.isVisible()) {
                        nameWidget.interact("Hello Visty");
}

Here is an example of how the method can look like. Read Apaec's post, and compare it to the snippet I've created to have a good understanding.

Thanks brother

Edit: figured it out, thanks!

Edited by phony

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.