Jump to content

Trouble with looting the last item


Spider Scripts

Recommended Posts

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

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

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

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