Jump to content

Returning an array of Inventory Items?


Varies

Recommended Posts

Hello, once again I come with a question but this time regarding the Inventory.

 

I was surfing the API when I wanted to find out if it was possible to return the id of an item in a specific slot OR return the entire array of items held in ones inventory.

 

Thanks for any help, I have found the Item[] getItems() and then getSlot(). If somone could help clarify the use for these and how one could use them for an array that would be great.

 

Thanks again OSBot community.

Link to comment
Share on other sites

Hello, once again I come with a question but this time regarding the Inventory.

 

I was surfing the API when I wanted to find out if it was possible to return the id of an item in a specific slot OR return the entire array of items held in ones inventory.

 

Thanks for any help, I have found the Item[] getItems() and then getSlot(). If somone could help clarify the use for these and how one could use them for an array that would be great.

 

Thanks again OSBot community.

getItems(); returns an array of type Item.

 

what do you plan on doing?

 

 

Precise

Link to comment
Share on other sites

getItems(); returns an array of type Item.

 

what do you plan on doing?

 

 

Precise

 

I basically plan on grabbing all the ids from the inventory and loading it into an array in which if the person needs to stock up with that exact load out they started with, it will withdraw that same load out by going through the array.

 

The getItems() is an Items array, how would I turn that into an int.

Link to comment
Share on other sites

I basically plan on grabbing all the ids from the inventory and loading it into an array in which if the person needs to stock up with that exact load out they started with, it will withdraw that same load out by going through the array.

 

The getItems() is an Items array, how would I turn that into an int.

 

may i ask, do you know the basics of java?

anyways:

int[] itemIds = new int[getInventory().getItems().length-1];

for (int i = 0; i < itemIds.length; i++) 
    itemIds[i] = getInventory().getItems()[i].getId();
  • Like 1
Link to comment
Share on other sites

may i ask, do you know the basics of java?

 

Yes, I've been coding in Java for around 5 years. Started on old clients but they had methods that allowed you to select the slot and return that id which would be easier for creating the array of items.

 

the getItems() like I said are held by the Items[] array which are held by inventory.

 

Like I was my question is, the Items array. If I did         Item[] temp = inventory.getItems();

then returned the size of temp and put it into a loop, would it be spitting out integers or more?

 

may i ask, do you know the basics of java?

anyways:

int[] itemIds = new int[getInventory().getItems().length-1];

for (int i = 0; i < itemIds.length; i++) 
    itemIds[i] = getInventory().getItems()[i].getId();

 

Also thanks for that, still reviewing this api. A bit more lengthy then some I have seen but it's a lot more accurate.

  • Like 1
Link to comment
Share on other sites

So confusing on what you want..so I'll do my best.

 

Usage for grabbing the players inventory as an Item array:

inventory.getItems()

 

Since you want to store their initial setup, I'd do something like:

initial = inventory.getItems()
upon startup

 

To grab the amount of an item object (returned as an integer), simply do:

item.getAmount()
 

 

Put it all together, you should end up with something like this:

for (int i = 0; i < inventory.getItems().length; i++) {
Item current = inventory.getItems()[i]; //the current item in the respective slot
Item in = initial[i];  //the initial item in the respective slot
//probably want to skip iteration if the item is null but idk
if (in.getAmount() != current.getAmount()) { //if the initial amount is different to the current amount...
bank.withdraw(current.getId(), in.getAmount() - current.getAmount()); //withdraw the necessary amount
}
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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