September 14, 20241 yr 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."); }
September 14, 20241 yr 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)
September 15, 20241 yr Author 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.
September 17, 20241 yr 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, 20241 yr by yfoo
September 20, 20241 yr Author 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.
Create an account or sign in to comment