timepudding Posted September 14 Share Posted September 14 I’m working on a script that crafts earth battlestaffs. The script currently selects an orb and then a battlestaff from my inventory. However, I’m facing an issue where the script always selects the first battlestaff in the inventory instead of the one closest to the orb. the current script interacts with first one I want it to interact with the last one Item battleStaff = inventory.getItem(ITEM_BATTLESTAFF); Item earthOrb = inventory.getItem(ITEM_EARTHORB); if (battleStaff.interact(ACTION_SELECTITEM)) { sleep(random(400, 600)); if (earthOrb.interact(ACTION_SELECTITEM)) { sleep(random(700, 900)); return true; } else { log("Error: Failed to interact with Earth Orb."); } } else { log("Error: Failed to interact with Battle Staff."); } Quote Link to comment Share on other sites More sharing options...
Fanny Posted September 14 Share Posted September 14 private Item selectItemFromInventory(String itemName) { List<Integer> itemSlots = new ArrayList<>(); for (int i = 1; i <= 28; i++) { if (getInventory().getItemInSlot(i) != null && getInventory().getItemInSlot(i).getName().equals(itemName)) { itemSlots.add(i); } } // If the item exists in any slot, return the last one if (!itemSlots.isEmpty()) { int lastSlotIndex = itemSlots.get(itemSlots.size() - 1); // Get the last index return getInventory().getItemInSlot(lastSlotIndex); // Return the last item } // Return null if no item was found return null; } Just off the top of my head (untested) Quote Link to comment Share on other sites More sharing options...
timepudding Posted September 15 Author Share Posted September 15 10 hours ago, Fanny said: private Item selectItemFromInventory(String itemName) { List<Integer> itemSlots = new ArrayList<>(); for (int i = 1; i <= 28; i++) { if (getInventory().getItemInSlot(i) != null && getInventory().getItemInSlot(i).getName().equals(itemName)) { itemSlots.add(i); } } // If the item exists in any slot, return the last one if (!itemSlots.isEmpty()) { int lastSlotIndex = itemSlots.get(itemSlots.size() - 1); // Get the last index return getInventory().getItemInSlot(lastSlotIndex); // Return the last item } // Return null if no item was found return null; } Just off the top of my head (untested) nah, it still selects first battle staff. I tried using Item battleStaff = inventory.getItemInSlot(13); , but it still selects the first battlestaff. Quote Link to comment Share on other sites More sharing options...
yfoo Posted September 17 Share Posted September 17 (edited) Use ```inventory.interact(13,"Use"))``` To select slot 13. followed by ```inventory.interact(14, USE)```. Here is how I dod mine private boolean combineComponents() throws InterruptedException { int[] slotPair = getInvSlotPair(); Item item1 = inventory.getItemInSlot(slotPair[0]); Item item2 = inventory.getItemInSlot(slotPair[1]); boolean notNull = item1 != null && item2 != null; boolean notSameItem = notNull && item1.getId() != item2.getId(); // Assert Item1 and 2 are the equivalent items determined at script start (ItemA and B). // Not foolproof, but a simple method boolean sumTo0 = notNull && (item1.getId() + item2.getId() - itemA.getId() - itemB.getId() == 0); boolean canUseSlotPair = notSameItem && sumTo0; if (canUseSlotPair && inventory.interact(slotPair[0], USE)) { ScriptPaint.setStatus("ItemA -> ItemB"); sleep(randomGaussian(300, 100)); return inventory.isItemSelected() && inventory.interact(slotPair[1], USE); } else { ScriptPaint.setStatus("ItemA -> ItemB w/ backup interaction"); if (inventory.interact(USE, itemA.getId())) { sleep(randomGaussian(300, 100)); return inventory.isItemSelected() && inventory.interact(USE, itemB.getId()); } } return false; } Edited September 17 by yfoo Quote Link to comment Share on other sites More sharing options...
timepudding Posted September 20 Author Share Posted September 20 On 9/17/2024 at 6:53 PM, yfoo said: Use ```inventory.interact(13,"Use"))``` To select slot 13. followed by ```inventory.interact(14, USE)```. Here is how I dod mine private boolean combineComponents() throws InterruptedException { int[] slotPair = getInvSlotPair(); Item item1 = inventory.getItemInSlot(slotPair[0]); Item item2 = inventory.getItemInSlot(slotPair[1]); boolean notNull = item1 != null && item2 != null; boolean notSameItem = notNull && item1.getId() != item2.getId(); // Assert Item1 and 2 are the equivalent items determined at script start (ItemA and B). // Not foolproof, but a simple method boolean sumTo0 = notNull && (item1.getId() + item2.getId() - itemA.getId() - itemB.getId() == 0); boolean canUseSlotPair = notSameItem && sumTo0; if (canUseSlotPair && inventory.interact(slotPair[0], USE)) { ScriptPaint.setStatus("ItemA -> ItemB"); sleep(randomGaussian(300, 100)); return inventory.isItemSelected() && inventory.interact(slotPair[1], USE); } else { ScriptPaint.setStatus("ItemA -> ItemB w/ backup interaction"); if (inventory.interact(USE, itemA.getId())) { sleep(randomGaussian(300, 100)); return inventory.isItemSelected() && inventory.interact(USE, itemB.getId()); } } return false; } Your solution worked. Thanks. Quote Link to comment Share on other sites More sharing options...