- Joined
- Oct 24, 2015
- Messages
- 82
- Thread Author
- #1
In this tutorial i will show you how too:
1) Create an Area
I'm going to do it in terms of a bank but you can change it to your needs!
To create and area, in a way just copy me:
To find the Coordinates use the Area maker or this one!
2.) Select random Coordinate in area
Ok so this is easy once you know what you are doing!
Simple as that, just make sure "bank." is the same as what you defined the Area to be.
3.) Create a path
Next you need to create a path you can use what you want, a Bresenham Path or a Region Path i prefer a region path as my bank is close by!
As "Baddest Man on Earth" pointed out:
For a Bresenham Path just replace "RegionPath" with "BresenhamPath"
4.) Walk There!
This is the easiest part!
Just a null check to see if it fails and then it walks there!
All the code together looks like this:
Hope this has helped anybody that needed it! If you have any questions ask away!
- Create an Area
- Select random Coordinate in area
- Create a path to Coordinate
- Walk there!
1) Create an Area
I'm going to do it in terms of a bank but you can change it to your needs!
To create and area, in a way just copy me:
Code:
final Area bank = new Area.Rectangular(new Coordinate(xxxx, xxxx, 0), new Coordinate(xxxx, xxxx, 0)); // Bank area
2.) Select random Coordinate in area
Ok so this is easy once you know what you are doing!
Code:
final Coordinate destination = bank.getRandomCoordinate();
3.) Create a path
Next you need to create a path you can use what you want, a Bresenham Path or a Region Path i prefer a region path as my bank is close by!
As "Baddest Man on Earth" pointed out:
- RegionaPath can only be generated if the destination is in the current loaded Region. You should always have a failsafe BreshnamPath or WebPath
Code:
final RegionPath pathtobank = RegionPath.buildTo(destination); // Sets path
4.) Walk There!
This is the easiest part!
Code:
if (pathtobank != null)
pathtobank.step(true); // goes to the bank
All the code together looks like this:
Code:
final Area bank = new Area.Rectangular(new Coordinate(xxxx, xxxx, x), new Coordinate(xxxx, xxxx, x)); // Bank area
if (!Bank.isOpen()) { // Check if bank is open
final Coordinate destination = bank.getRandomCoordinate(); // Gets random Coordinate in area
final RegionPath pathtobank = RegionPath.buildTo(destination); // Sets path
if (pathtobank != null)
pathtobank.step(true); // goes to the bank
}
Hope this has helped anybody that needed it! If you have any questions ask away!
Last edited: