Skip to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Selecting the Closest Battlestaff in crafting script

Featured Replies

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

image.png.fc12b7c99a856fc6232cfb196e534aab.png

I want it to interact with the last one

image.png.8464e8709e50b30d544acf82404bad04.png

 

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.");
        }

 

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)

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

 

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 by yfoo

  • 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

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.