xVril 16 Share Posted May 20, 2020 Hi, I have a scenario that requires the player has at least 3 empty inventory spaces. There are a number of items that the inventory will contain that I do not need so I created a custom filter for this: public static final Filter<Item> ITEMS_TO_DROP = item -> item.getID() == 1 || item.getID() == 2 || item.getID() == 3 || item.getID() == 4 || item.getID() == 5 || item.getID() == 6; I use the following check if (s.getInventory().emptySlotCount() < 3) { s.getInventory().dropAll(Filters.ITEMS_TO_DROP); } This works fine and will drop these items when the inventory is full, the issue occurs when I have an empty slot. Any ideas or will I just have to check each inventory slot individually to see if it is empty? Link to comment Share on other sites More sharing options...
Pseudo 179 Share Posted May 20, 2020 Public String[] junkItems = {}; If (empty slots < threshold) { For (Item i: inventoryitems) { For (string s : junkItems) { If (I! = null and I.getName().contains(s)) { Drop I } } } Excuse the formatting/Pseudo code, written in reply box on phone. The above will iterate over inventory items, if an items name matches one of those present in the string array then drop it. Link to comment Share on other sites More sharing options...
xVril 16 Author Share Posted May 20, 2020 5 hours ago, Pseudo said: Public String[] junkItems = {}; If (empty slots < threshold) { For (Item i: inventoryitems) { For (string s : junkItems) { If (I! = null and I.getName().contains(s)) { Drop I } } } Excuse the formatting/Pseudo code, written in reply box on phone. The above will iterate over inventory items, if an items name matches one of those present in the string array then drop it. Thanks for your help. Managed to get a solution based on your response. for(Item i : s.getInventory().all()) { if(Filters.ITEMS_TO_DROP.match(i)) { s.getInventory().drop(i.getID()); } } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.