Jump to content

World hop issue - please help


Recommended Posts

Posted (edited)

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
  • WhyO changed the title to World hop issue - please help
  • 3 weeks later...
Posted

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

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