Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • getCurrentMenuOptions / Randomize which GroundItem to interact with on the same Tile?


    holic

    Recommended Posts

    Just trying to figure out how to randomize which GroundItem gets interacted with when they're on the same tile. Right now, I can't seem to select any entry other than the first appearance of the item in the menu regardless of which one I'm targeting.

    Here's a snippet trying to randomize it:

    GroundItem[] g2 = getGroundItems().getItemsOnTile(g.getTile());
    if (g2 != null) {
        ArrayList<GroundItem> myList = new ArrayList<GroundItem>();
        for (GroundItem t : g2) {
            if (t.getName().equals(g.getName()))
                myList.add(t);
        }
        if (myList.size() > 1) {
            g = myList.get(Calculations.random(0, myList.size()));
            log("Target randomized: " + g.getName());
        }
    }

    So I decided I would do it manual (i.e. Open a the menu at the specified tile, get menu entries, match entries against the target item and click a random menu index that matches) but it seems like there must be a cleaner solution. I just started to throw this together but before I could continue on it I realized there's an issue: getMenuOptions get ALL menu options around, not just from the currently open menu so it doesn't know which option to click.

    Is there a getCurrentMenuOptions()?

    private boolean manualInteract(GroundItem g, String option) {
            GroundItem[] g2 = getGroundItems().getItemsOnTile(g.getTile());
            if (g2 != null) {
                ArrayList<GroundItem> items = new ArrayList<GroundItem>();
                for (GroundItem t : g2) {
                    if (t.getName().equals(g.getName()))
                        items.add(t);
                }
                if (items.size() <= 1) {
                    return g.interact(option.trim());
                } else {
                    getMouse().move(g.getClickablePoint());
                    sleep(100, 500);
                    getMouse().click(true);
                    if (getMenu().open()) {
                        sleep(50, 500);
                        if (getMenu().isMouseOnAction(option + g.getName())) {
                            sleep(50, 100);
                            getMouse().click();
                        } else {
                            int index = 0;
                            ArrayList<Integer> menuIndexes = new ArrayList<Integer>();
                            String[] menuOptions = getMenu().getMenuOptions();
                            for (String t : menuOptions) {
                                if (t != null) {
                                    //log("Menu option: " + t);
                                    if (t.contains(g.getName())) {
                                        menuIndexes.add(index);
                                        log("Menu index for " + g.getName() + ": " + index);
                                    }
                                    index++;
                                }
                            }
                            if (menuIndexes.size() > 1) {
                                sleep(150, 250);
                                log("Target randomized: " + g.getName());
                                return (getMenu().clickIndex(menuIndexes.get(Calculations.random(0, menuIndexes.size()))));
                            }
                        }
                    } else {
                        log("Failed at open()");
                    }
                }
            }
            return false;
        }

     

    Any advice would be awesome 

    Link to comment
    Share on other sites

    3 hours ago, Pseudo said:

    So what you're doing doesn't work? Or?

    Nope it doesn't. My method to randomize the grounditems doesn't randomize, it clicks the first entry.

    And my method to manually click it doesn't work either because getMenuOptions gets all menu options, not the open menu's.

     

    Looking for suggestions.

    Link to comment
    Share on other sites

    Figured out I needed to be calling getMenuRows() not getMenuOptions()

    I've updated the original post with the snippet should anyone want it, it could definitely be improved though.

    Link to comment
    Share on other sites

    Nm, I can't update my post so here's the snippet

     

     private boolean manualInteract(GroundItem g, String option) {
            GroundItem[] g2 = getGroundItems().getItemsOnTile(g.getTile());
            if (g2 != null) {
                ArrayList<GroundItem> myList = new ArrayList<GroundItem>();
                for (GroundItem t : g2) {
                    if (t.getName().equals(g.getName()))
                        myList.add(t);
                }
                if (myList.size() <= 1) {
                    return g.interact(option.trim());
                } else {
                    getMouse().move(g.getClickablePoint());
                    sleep(100, 500);
                    getMouse().click(true);
                    if (getMenu().open()) {
                        sleep(50, 500);
                        if (getMenu().isMouseOnAction(option + g.getName())) {
                            sleep(50, 100);
                            getMouse().click();
                        } else {
                            int index = 0;
                            ArrayList<Integer> menuIndexes = new ArrayList<Integer>();
                            List<MenuRow> rows = getClient().getMenu().getMenuRows();
                            for (MenuRow row : rows) {
                                if (row.getAction().equals(option) &&  row.getObject().contains(g.getName())) {
                                    menuIndexes.add(index);
                                    //log("Menu index for " + g.getName() + ": " + index);
                                }
                                index++;
                            }
                            if (menuIndexes.size() > 1) {
                                sleep(150, 250);
                                log("Target randomized: " + g.getName());
                                return (getMenu().clickIndex(menuIndexes.get(Calculations.random(0, menuIndexes.size()))));
                            }
                        }
                    } else {
                        log("Failed at open()");
                    }
                }
            }
            return false;
        }

     

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.