- Thread Author
- #1
Anyone who has ever tried to write a script that hovers the next object while waiting for the current task to be completed has probably noticed that most APIs make it relatively difficult to get the second object.
In an effort to make this task simpler I have added a Sort class to the API.
The following are examples of how to get the second nearest tree and man, but the concept can be expanded to get the third, fourth, fifth, and so on.
Edit: There are now two ways to easily do this:
Edit2: Now there are three:
The same can be done with GroundItems, Projectiles, Players, and any other type of Locatable.
In an effort to make this task simpler I have added a Sort class to the API.
The following are examples of how to get the second nearest tree and man, but the concept can be expanded to get the third, fourth, fifth, and so on.
Edit: There are now two ways to easily do this:
Edit2: Now there are three:
Java:
LocarableQueryResults<GameObject> results = GameObjects.getLoaded("Tree").sortByDistance();
if(results.size()>=2){
final GameObject secondNearestTree=results.get(1);
}
Java:
List<GameObject> trees = Sort.byDistance(GameObjects.getLoaded("Tree"));
if (trees.size() >= 2) {
final GameObject secondNearestTree = trees.get(1);
}
Java:
GameObjects.getLoaded("Man").sortByDistance().get(1);
Last edited: