Spider Scripts Posted September 19, 2018 Share Posted September 19, 2018 (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. 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 September 19, 2018 by Spider Quote Link to comment Share on other sites More sharing options...
Night Posted September 19, 2018 Share Posted September 19, 2018 (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 September 19, 2018 by Night Quote Link to comment Share on other sites More sharing options...
Juggles Posted September 19, 2018 Share Posted September 19, 2018 Yeah menu class as Night stated. Open menu -> click last option Quote Link to comment Share on other sites More sharing options...
Spider Scripts Posted September 20, 2018 Author Share Posted September 20, 2018 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 Quote Link to comment Share on other sites More sharing options...