Jump to content

Trouble with looting the last item


Recommended Posts

Posted (edited)

I'm working on a looting script. 

let's say I do 

 GroundItem tuna = getGroundItems().closest("tuna");

and there are 10 tunas that are close to me (have the same X and Y positions) 

now Instead of  looting starting from the first tuna, I want to loot starting from the last tuna. :xboge:

I'm usually able to find my way around the documentation easily but I can't seem to find a way to do this and I'm sure there must be some clean way to do it.

My attempt for a general function was something like this. (you might want to skip that)

Spoiler

public GroundItem selectLastItem(String itemName) {
 GroundItem item = getGroundItems().closest(itemName); //because I'll need the X and Y position of the closest tuna to get the full list

 List < GroundItem > items = getGroundItems().get(item.getX(), item.getY()); //get list of all items in the position of the closest tuna

 for (int i = items.size(); i >= 0; i--) {
  if (items.get(i).getName().equals(itemName)) {
   return items.get(i); //return last the last item in the list
  }
 }
 return null;

}
GroundItem tuna = selectLastItem("Tuna"); //then call the function like this
tuna.interact("Take"); //interact with the last tuna

 

Thanks a lot in advance! 

Edited by Spider
Posted (edited)

I would use getGroundItems().getAll(), stream the results and filter through them for Tuna or whatever items. You can them sort this List using a comparator and your player's distance to the GroundItem.

EDIT: I read the question wrong, I would check out the Menu class.

Edited by Night
Posted
On 9/19/2018 at 3:40 AM, Night said:

I would use getGroundItems().getAll(), stream the results and filter through them for Tuna or whatever items. You can them sort this List using a comparator and your player's distance to the GroundItem.

EDIT: I read the question wrong, I would check out the Menu class.

 

On 9/19/2018 at 8:13 AM, Juggles said:

Yeah menu class as Night stated. Open menu -> click last option 

awesome thanks guys

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