Jump to content

Help with world hopping in script


Recommended Posts

Posted (edited)

So I have made a very beginner script but it did the job until I wanted to add world hopping.

Each time my code is executing, the script doesn't wait for the world hopping to take place, it just opens the world hopping menu and goes to trade once again.

I tried adding sleeps too after "worldHop1" but it only made the world hopping take this amount of time and still didn't even hop afterwards, just trades again.

I would really appreciate it if someone can help me regarding this!

Here is the part of my script that I am talking about:

@Override
public int onLoop() throws InterruptedException {



    isReadyToTrade();
    trade();
    sleep(3000);
    Buy();
    sleep(3000);
    ExitStore();
    sleep(5000);
    checkInventory();
    sleep(3000);
    worldHop1();



    return 0;

    
}



public void worldHop1(){
    getWorlds().hop(308);

    }
Edited by mrdukesilver
Posted (edited)

@mrdukesilver

Without having knowledge of the code inside of the other methods, this will be rather hard to debug.

Try executing only the worldHop1 method without executing any other code to see if it functions as expected.

I also recommend to look into the ConditionalSleep classes.

Standard ConditionalSleep class

 new ConditionalSleep(maxSleepTime, checkInterval) {
     @Override
     public boolean condition() throws InterruptedException {
         return condition;
     }
 }.sleep();

Non-Standard ConditionalSleep class - I personally recommend using this one, as it is more straightforward.

ConditionalSleep2.sleep(maxSleepTime, () -> condition)

 

Edited by BravoTaco
  • 2 weeks later...
Posted
On 2/5/2022 at 1:47 AM, BravoTaco said:

@mrdukesilver

Without having knowledge of the code inside of the other methods, this will be rather hard to debug.

Try executing only the worldHop1 method without executing any other code to see if it functions as expected.

I also recommend to look into the ConditionalSleep classes.

Standard ConditionalSleep class

 new ConditionalSleep(maxSleepTime, checkInterval) {
     @Override
     public boolean condition() throws InterruptedException {
         return condition;
     }
 }.sleep();

Non-Standard ConditionalSleep class - I personally recommend using this one, as it is more straightforward.

ConditionalSleep2.sleep(maxSleepTime, () -> condition)

 

Hey! , tysm for responding, can u tell me how can I use this in my code, could you kindly provide me an example pls?

Posted (edited)
On 2/17/2022 at 2:04 PM, mrdukesilver said:

Hey! , tysm for responding, can u tell me how can I use this in my code, could you kindly provide me an example pls?

Sure! No problem!

// Basic code to chop a regular tree, with a conditional sleep, when the player is not animating.
if (!myPlayer().isAnimating()) {
    RS2Object tree = getObjects().closest("Tree");
    if (tree != null && tree.interact("Chop down")) {
        // The conditional sleep returns true or false.
        // True being returned if the condition is met. IE. The player is animating.
        // False being returned if the condition is not met, and the max sleep time is met.
        // The sleep time is in milliseconds so 15000 == 15 seconds.
        if (ConditionalSleep2.sleep(15000, () -> myPlayer().isAnimating())) {
            log("Player is chopping the tree.");
        }
    }
}
Edited by BravoTaco

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