Jump to content

How to walk a random predefined path?


Recommended Posts

Posted

So I understand how to declare a path, and walk the path. What I'm trying to do is declare 3 paths that all go to the same location, but using different tile combinations, and then make my script randomly select a path to take, making it more random, and less boy like.

Has Java got a built in random function that I can tell it to return a random between 0 and 2, and then make it walk the path correlating to that number? Sorry if I'm being confusing

Posted
8 hours ago, Chris said:

 

8 hours ago, Khaleesi said:

public static int randInt(int min, int max) {
    Random rand = new Random();
   return rand.nextInt((max - min) + 1) + min;
}

Thank you for the help guys!

 

 

8 hours ago, Jarl said:

Like chris mentioned, you can use Random.nextInt(3) or osbot's random(0,2).


If your 3 paths are similar, you probably don't need to do this kind of thing because osbot doesn't always click on the exact same tiles.

Yeah, I appreciate that, just thought that it couldn't hurt to make my script seem more random, right?

Posted
List<Position> pathToSewer = new ArrayList<>();
@Override
public void onStart() {
    log("Let's get started!");
    pathToSewer.add(new Position(3246, 3433, 0));
    pathToSewer.add(new Position(3246, 3450, 0));
    pathToSewer.add(new Position(3238, 3457, 0));
}
public int onLoop() throws InterruptedException {
    if (varrockBank.contains(myPlayer()) && !getInventory().isFull())
    {
        log("Walking to sewer");
        getWalking().walkPath(pathToSewer);
    }
    return random(2000, 5000);
}

 

So i'm using the walkPath function, but basically, it walks my player to the first position on the path, and even once I reach the tile, the script clicks on the exact tile to ensure I have moved to it. It doesn't do this for any other position of the path? Anyone know what could be causing this?

Posted
On 1/9/2021 at 7:04 AM, mitsuki said:

Do I need to spread the positions out even more? They are already only just visible by zooming all the way out

No. Your positions were too spread out. You need to make the positions closer for the part where the script keeps clicking on the same tile.

  • Like 1
Posted

Is there any other way to declare the path before the onstart or onloop? I currently just add all of the positions of the path in onStart with: 

@Override
public void onStart() {
    log("Let's get started!");
    pathToSewer.add(new Position(3246, 3433, 0));
    pathToSewer.add(new Position(3246, 3450, 0));
    pathToSewer.add(new Position(3238, 3457, 0));
}

But is there any other way to declare it outside of the loops? Or is adding each position on startup the best method?

Posted (edited)
1 hour ago, mitsuki said:

?

I thinks this will work 

static{
    pathToSewer.add(new Position(3246, 3433, 0));
    pathToSewer.add(new Position(3246, 3450, 0));
    pathToSewer.add(new Position(3238, 3457, 0));
}

or

    List<Position> pathToSewer = new ArrayList<Position>(Arrays.asList(new Position[]{new Position(3246, 3433, 0), new Position(3246, 3450, 0), new Position(3238, 3457, 0)}));

or use 

https://explv.github.io/?centreX=3108&centreY=3315&centreZ=0&zoom=7

Edited by Nbacon
  • Like 1
Posted
private static final List<Position> PATH_TO_SEWER = Arrays.asList(
            new Position(3246, 3433, 0),
            new Position(3246, 3450, 0),
            new Position(3238, 3457, 0)
    );

You can put this at the top, inside the class but outside the methods. It is not a must but it is a good idea to follow java naming conventions. Constants should be declared in capitals.

  • Like 1

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