Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Best way to generate a random path to a position?

Featured Replies

Right now I think I'm doing it in a really hacky way and I'd hope there would be better ways than doing it.

 

Right now I'm basically doing;

int rand1 = random(0, 10) - 5;
int rand2 = random(0, 30) - 15;
Position randomPath = new Position((baseObject.getX() + rand1), (baseObject.getY() + rand2), 0);

if (map.canReach(randomPath)){
    localWalker.map.walk(randomPath);
}

This is for getting into view of the object itself so it can be interacted with later. Would there be better ways than doing this to get to a object not yet visible but I have the known coord's for?

1) you are not generating a path, you are generating a position, a single position.

2) you are making the x and y positions have a variance, if you happen to generate a random position that is not walkable, then the if statement will not execute.

3) if the position is too far to walk to then it will do nothing. 

 

LocalWalker will not take you cross regions without a path unless the region is cached, then it might (depends on client implementation).

If you are trying to walk a path, you need to give it a path. This will walk from one single point (the player) to the sudo random position that you are generating within the same region.

 

If that is what you want to do then this will kind of work maybe sometimes. tongue.png

 

Edited by Mysteryy

  • Author

1) you are not generating a path, you are generating a position, a single position.

2) you are making the x and y positions have a variance, if you happen to generate a random position that is not walkable, then the if statement will not execute.

3) if the position is too far to walk to then it will do nothing. 

 

LocalWalker will not take you cross regions without a path unless the region is cached, then it might (depends on client implementation).

If you are trying to walk a path, you need to give it a path. This will walk from one single point (the player) to the sudo random position that you are generating within the same region.

 

If that is what you want to do then this will kind of work maybe sometimes. tongue.png

 

Was a quick example not actually what I use >.> the random position is run in a while loop until it finds a correct one and the area this used is in its own sub-area of the map like minigames.

 

I'd like to however be able to fix your 3rd point out of it not working if its too far away which is what I want to resolve by generating a path to that position.

Perhaps what you might find easier is having a handful of pre-recorded paths, maybe 2 or 3, each slightly different, and when walking the path it would pick a random one of the three each time. As far as randomisation goes, that's not a too bad way of doing it, and its nice and simple too

 

Apaec

Was a quick example not actually what I use >.> the random position is run in a while loop until it finds a correct one and the area this used is in its own sub-area of the map like minigames.

 

I'd like to however be able to fix your 3rd point out of it not working if its too far away which is what I want to resolve by generating a path to that position.

 

 

What you are asking goes far beyond a simple explanation. I would suggest doing what apaec said, you should start with defining some paths and pick between them. 

 

On a side note, if you have a while loop generating the random position until it gets one that is walkable, you may get stuck in an infinite loop where there is never a walkable tile. Generally speaking while loops arent a great thing to use in scripts. I try to avoid them most of the time, and when I do use them I always add a watchdog timer. 

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.