Jump to content

Help with world hopping in script


mrdukesilver

Recommended Posts

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
Link to comment
Share on other sites

@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
Link to comment
Share on other sites

  • 2 weeks later...
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?

Link to comment
Share on other sites

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