Jump to content

The script works, but using the range takes too long, and the getwidget only happens the second time it appears


Recommended Posts

Posted

Hey guys, I've been working on a script that cooks at the lumbridge kitchen (after cooks assistant quest). The script works, but the two main problems I have with it are as follows:

1. When it clicks on "Raw shrimps" in the inventory, it seems to freeze, and doesn't use it with the range for like 8+ seconds, which seems really bot like.

2. When the widget comes up over the dialogue box, it doesn't detect it, so it uses the raw shrimps with the range a second time, then detects it.

Anyone know why it is doing this? I thought my code seemed fine?

Below is my script, thank you in advance dudes.

import javax.swing.JOptionPane;

import org.osbot.rs07.accessor.XInteractableObject;
import org.osbot.rs07.api.Bank;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.utility.ConditionalSleep;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.Keyboard;
import org.osbot.rs07.script.API;
import org.osbot.rs07.api.Dialogues;
import org.osbot.rs07.api.Widgets;

import java.awt.*;
import java.awt.event.KeyEvent;
import org.osbot.rs07.api.Dialogues;

@ScriptManifest(author = "Mitsuki", info = "CodeTest", name = "CodeTest", version = 0, logo = "")
public class Main extends Script {

    public Area lumbridgeKitchen = new Area(3206, 3212, 3211, 3216);

    private RS2Widget getMyWidget() {
        RS2Widget cookShrimpWidget = getWidgets().get(270, 14);
        return cookShrimpWidget;
    }

    private boolean isMyWidgetWorking() {
        return getMyWidget() != null && getMyWidget().isVisible();
    }

    @Override
    public void onStart() {
        log("Let's get started!");
    }

    @Override
    public int onLoop() throws InterruptedException {
        if (lumbridgeKitchen.contains(myPlayer()) && getInventory().contains("Raw shrimps")) {
            getInventory().getItem("Raw shrimps").interact("Use");
            if (getInventory().isItemSelected() == true) {
                RS2Object range = getObjects().closest("Cooking range");
                range.interact("Use");
                if (isMyWidgetWorking()) {
                    log("Widget time");
                    getMyWidget().interact("Cook");
                }
            }
        }
        return random(5000, 10000);
    }

    @Override
    public void onExit() {
        log("Thanks for running my AutoShrimper!");
    }
}

Btw, all of the imports are there, even though they aren't being used, as this is my testcode file. 

Posted (edited)

1. the return value is how long the script waits between the loops, so every time your script loops its going to wait for 5-10sec based on your code.

2. You have no sleeps at all in your script so it will try to do everything as soon as possible but it takes a minimum of 1tick (0.6s) before anything changes ingame for most things, so your 2nd if statement is simply going to be false on the first loop

 read this, especially the sleep part

Edited by ez11
  • Like 1
Posted
5 minutes ago, ez11 said:

1. the return value is how long the script waits between the loops, so every time your script loops its going to wait for 5-10sec based on your code.

2. You have no sleeps at all in your script so it will try to do everything as soon as possible but it takes a minimum of 1tick (0.6s) before anything changes ingame for most things, so your 2nd if statement is simply going to be false on the first loop

 read this, especially the sleep part

okay, thank you for the advice!

PS. did you learn java before writing scripts? or did you learn through this? Cheers, Mitsuki

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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