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.

API Issue | Inventory#isEmptyExcept(String[] items)

Featured Replies

820e813dda218e9cc67245f6508da409.png

 

 

Sorry I missed the error; ArrayIndexOutofBounds is the exception being thrown. 

 

There is a single line of code causing this: if(!inventory.isEmptyExcept(itemsString))

 

inventory is null checked, and itemsString is a String[].

 

The exception is coming from Inventory#isEmptyExcept(String[] s)

 

I made a new method and used it and it worked fine.

 

Working method: 

 

Code:


import org.osbot.rs07.api.Inventory;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.Script;

/**
 * Created by zach on 1/30/15.
 */
public class Inven {
    private Script script;

    public Inven(Script script){
        this.script = script;
    }

    /**
     * Checks if the inventory is empty with the exception of exceptItems.
     *
     * @param exceptItems the items to ignore when checking for an empty inventory.
     *
     * @return true if the inventory is empty or only contains some or all of the items
     * specified by except items, if the inventory contains anything other than an item
     * specified in exceptItems, returns false.
     */
    public boolean isExmptyExcept(String[] exceptItems){
        Inventory inventory = script.getInventory();
        if(inventory != null){
            if(28 - getEmptySlots() == getAmountExcludingStacks(exceptItems))
                return true;
        }
        return false;
    }

    /**
     * Gets the amount of a certain item ignoring stacks.
     *
     * @param item the item name to get the amount of.
     * @return the amount of the specified item that your inventory contains.
     * If the item is a stacked item, it will only be counted once instead of
     * the amount contained by the stack.
     */
    public int getAmountExcludingStacks(String item){
        Inventory inventory = script.getInventory();
        int amount = 0;
        if(inventory != null && item != null){
            for(int i = 0; i < 28; i++){
                Item tempItem = null;
                if((tempItem = inventory.getItemInSlot(i)) != null){
                    String tempItemName;
                    if((tempItemName = tempItem.getName()) != null && tempItemName.equals(item)){
                        amount++;
                    }
                }
            }
        }
        return amount;
    }

    /**
     * Gets the total amount for all items contained in items
     * excluding stack amounts.
     *
     * @param items the array of items to count.
     * @return the sum of the individual amounts for each item listed in items
     * that the players inventory contains, ignoring stack amounts.
     */
    public int getAmountExcludingStacks(String[] items){
        int amount = 0;
        for(String s : items){
            amount += getAmountExcludingStacks(s);
        }
        return amount;
    }

    /**
     * Gets the amount of empty slots in the players inventory.
     *
     * @return the amount of empty slots in the inventory.
     */
    public int getEmptySlots(){
        Inventory inventory = script.getInventory();
        int amount = 0;
        if(inventory != null){
            for(int i = 0; i < 28; i++){
                Item tempItem = null;
                if((tempItem = inventory.getItemInSlot(i)) == null){
                    amount++;
                }
            }
        }
        return amount;
    }
}

Using     public int getAmountExcludingStacks(String[] items):

140a391ddc78c90f807cb69e6ffc464e.png

cd2b300b4e3595d2a72d483b28f2ebc9.png

 

Im guessing there is something inside of the method returning -1. I am using getAmount inside of my custom method and it works fine. 

 

 

 

Note: This seems to only happen when the inventory is empty and the method is used.

Edited by Mysteryy

Incase you're using the workaround method, I dont think it'll work if one or more of your 'exception items' are notes/stackable with more than 1 quantity

  • Author

Good job, had this in my questing script and noticed the same thing.

 

 

Incase you're using the workaround method, I dont think it'll work if one or more of your 'exception items' are notes/stackable with more than 1 quantity

 

 

You are absolutely correct. I wrote this last night when I was trying to go to bed, just wanted to make a post quick. 

I added an entire class with some methods to make it such that it will work no matter if the items are stacked or not. 

The code is in the OP now, thanks for pointing that out. ^_^

  • Author

I'm making some new methods at the moment.

Edit: I found a potentially large issue.

What is the issue related to?

Guest
This topic is now closed to further replies.

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.