Jump to content

How to walk a random predefined path?


mitsuki

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

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