Jump to content

Bank item visibility


Recommended Posts

Posted (edited)

Here is the code that I currently use:

public boolean isVisible(String name) {
        return getBank().isSlotVisible(bot, getBank().getSlot(name), getBank().getSlot(name));
    }

It returns whether the item is visible or not. However, if the item is in the first row, it will always return false. Any ideas what is wrong, or any better implementation for checking?

Edited by andrewboss
Posted (edited)
1 hour ago, Hannes7337 said:

I think it has something to do with the absolute slot value.

You could only use getbank.getslot(name) instead of getbank.isslotvissible(). If getslot returns null you know it's not there.

4

There is no way you could check if it is visible or not by that method. It will always return the slot number if exists, even if not visible.

Edited by andrewboss
Posted
14 hours ago, andrewboss said:

Here is the code that I currently use:


public boolean isVisible(String name) {
        return getBank().isSlotVisible(bot, getBank().getSlot(name), getBank().getSlot(name));
    }

It returns whether the item is visible or not. However, if the item is in the first row, it will always return false. Any ideas what is wrong, or any better implementation for checking?

 

isSlotVisible takes two different slots as parameters, the tab slot and the absolute slot https://osbot.org/api/org/osbot/rs07/api/Bank.html#isSlotVisible-org.osbot.rs07.Bot-int-int-

Right now you are passing absolute slot for both of the parameters, which is incorrect.

I don't think there is a public method in the API to get the tab slot, there is a private one though.

You can try the following code:

 

public boolean isVisible(int itemID) {
    return getBank().isSlotVisible(bot, getTabSlot(itemID), getBank().getSlot(itemID));
}

private int getTabSlot(final int itemId) {
    int tabForItem = getBank().getTabForItem(itemId);
    if (tabForItem == -1) {
        return -1;
    }
    Item[] itemsInTab = getBank().getItemsInTab(tabForItem);
    for(int i = 0; i < itemsInTab.length; i++) {
        if(itemsInTab[i] != null && itemsInTab[i].getId() == itemId) {
            return i;
        }
    }
    return -1;
}



 

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...