Jump to content

World hop issue - please help


WhyO

Recommended Posts

Hi!
I am very new to scripting, and my Java skills are below average to say the least, but I find myself enjoying it and it lets me actually spend time learning the language so I can one day get a job in it.
Anyway, I have an issue where my world hop function only lets my player hop once, and then never again. It tries, as the log says it is generating a new world to hop, but just gets stuck while doing it.
Osbot logs "[ERROR][Bot #1][03/02 12:33:41 PM]: Failed to scroll to world 508"

I wrote it in 3 different ways now, thinking its the way I write the hopping function, but since it always ends up getting my char stuck after the first hop, I kinda don't know where to look now.
Please don't mind my chaotic code, and if anybody can get through it and possibly find a bug I would be eternally grateful!
Btw there must be an issue with tradeWithUglugNar() function, as when I tried the script without it the player would hop constantly no problem.

worldHop() is being called in tradeWithUglugNar() function after stock amount check
 

Spoiler
@Override
public int onLoop() throws InterruptedException {
    walkToTrade();
    if (!getInventory().contains("Achey tree logs")) {
        tradeWithUglugNar();
    }
    makeShafts();


    return (random(600, 900));
}

private void tradeWithUglugNar() throws InterruptedException {

        if (getInventory().isEmpty() || !(getInventory().contains("Coins") || getInventory().getAmount("Coins") >= 200)) {
            bankStart();
        }
        NPC targetNpc = getNpcs().closest(npc -> npc.getName().equals("Uglug Nar"));
        if (targetNpc != null) {
            if (!targetNpc.isVisible()) {
                getCamera().toEntity(targetNpc);
            }
            if (targetNpc.interact("Trade")) {
                new ConditionalSleep(5000, 2000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getWidgets().containingText("Trading With") != null;
                    }
                }.sleep();
                sleep(random(1000,1400));
                if (getWidgets().containingText("Trading With") != null) {
                    if (store.getAmount("Achey tree logs") < 5 ){
                        worldHop();
                    }
                    if (getInventory().contains("Achey tree logs")) {
                        getWidgets().get(300, 1, 11).interact(); // Click "Close" button
                    } else {
                        if (getWidgets().get(300, 16, 3) != null) {
                            getWidgets().get(300, 16, 3).interact("Buy 50"); // Click "Offer-All" button
                            new ConditionalSleep(2000) {
                                @Override
                                public boolean condition() throws InterruptedException {
                                    return getInventory().contains("Achey tree logs");
                                }
                            }.sleep();
                        }sleep(random(200,500));
                        if (getWidgets().get(300, 1, 11) != null) {
                            getWidgets().get(300, 1, 11).interact(); // Click "Close" button
                        }
                        }

                }
            }
        }sleep(500); // Delay for 1 second before attempting to trade again


}


private void worldHop() throws InterruptedException {
    log("start");
    
    int[] swiaty = {310, 311, 312, 313, 315, 317, 318, 325, 327, 328, 333, 334, 341, 342, 343, 350, 351, 352, 358, 367, 368, 375, 376, 386, 395, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516};
    int x = getWorlds().getCurrentWorld();
    log(x);
    int y = swiaty[random(0, swiaty.length - 1)];
    log(y);
    if (x != y){
        getWorlds().hop(y);
        new ConditionalSleep(5000){
            @Override
            public boolean condition() throws InterruptedException {
                return false;
            }
        }.sleep();
    }
    else {
        while (y == x){
            y = swiaty[random(0, swiaty.length - 1)];
        }

    }



}

 

Edited by WhyO
Link to comment
Share on other sites

  • WhyO changed the title to World hop issue - please help
  • 3 weeks later...

I've had shop buying scripts act funny after closing the shop and trying to hop but opening the shop back up before selecting a world

I added a boolean 'NeedsToHop'
Start script with it as false. When the shop is out of stock flip it to true, and back to false when the player hops worlds.
Just have the script check if needs to hop if false and if so do what it does, if true hop

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