Varies Posted February 26, 2015 Share Posted February 26, 2015 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. Quote Link to comment Share on other sites More sharing options...
Precise Posted February 26, 2015 Share Posted February 26, 2015 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 Quote Link to comment Share on other sites More sharing options...
Varies Posted February 26, 2015 Author Share Posted February 26, 2015 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. Quote Link to comment Share on other sites More sharing options...
Precise Posted February 26, 2015 Share Posted February 26, 2015 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(); 1 Quote Link to comment Share on other sites More sharing options...
Varies Posted February 26, 2015 Author Share Posted February 26, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
Kaleem Posted February 27, 2015 Share Posted February 27, 2015 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 } } Quote Link to comment Share on other sites More sharing options...