I feel like I'm going crazy, cause I can't seem to find the script call for getting the number of items currently in a party's inventory. I figure it's likely separated by items, weapons, etc. but I'm just not finding the info, and my head might actually explode. I'm using a limited inventory script, and it doesn't have a call to check, and allows items to be added even when at limit. I wanted to try and fix this issue, but I need to be able to pull up those numbers! Thanks in advance for any assistance!
[SOLVED] Get Number of Items in Inventory
Javascript/Plugin Support$gameParty.numItems() should do the trick. $gameParty.numItems($dataWeapons[1]) will return how many of weapon 1 your party has.
Oh no worries. I used your generator parts in all my ace projects, it's the least I can do to help lol
Aww! Yay! I'm happy those are still being used!
Hmm... I seem to be having trouble getting the information to come up. Do I need to put some thing in the parenthesis for $gameParty.numItems()? I tried assigning it's value to a variable and got nothing. It works when I specifically put $dataWeapons[1] in the parenthesis, however.
By default, the engine puts every item in one of 3 "containers", depending on the type. $dataWeapons hold every weapon, $dataArmors holds every piece of armor, and $dataItems holds everything else.
If you look at the code for the numItems command, you'll notice it needs the item container, so to actually get a printed result you'd need to put one of the 3 containers in the parentheses and then the ID number from the editor.
If you look at the code for the numItems command, you'll notice it needs the item container, so to actually get a printed result you'd need to put one of the 3 containers in the parentheses and then the ID number from the editor.
Code:
Game_Party.prototype.numItems = function(item) {
var container = this.itemContainer(item);
return container ? container[item.id] || 0 : 0;
};
So, I'll essentially have to put together something that will take the amounts of each item, weapon, and armor individually and add them all up? Am I understanding correctly?
Why do you need to do this via script? Control Variables will do it for you.
Is there an option I'm missing that lets you obtain the total numbers of all items in inventory? I know I can do it one item at a time, but I feel like I may be able to do that more quickly with an array and loops or something like that. Am I wrong?
Code:
var totalItems = 0;
for(var i = 0; i < $dataWeapons.length; i++){
totalItems += $gameParty.numItems($dataWeapons[i]);
}
for(var i = 0; i < $dataArmors.length; i++){
totalItems += $gameParty.numItems($dataArmors[i]);
}
for(var i = 0; i < $dataItems.length; i++){
totalItems += $gameParty.numItems($dataItems[i]);
}
$gameVariables.setValue(1,totalItems);
This should do the trick. Counts up the total number of items and sets variable 1 to the value.
Yeah, you would do it more quickly via script call. Your post didn't make clear that you wanted the total number of every item in inventory.
I feel like you would be able to do it in a single statement using $gameParty._items and $gameParty._weapons and $gameParty._armors by combining the arrays then reducing, but it's not a command I've used often so I'm sure I'd get it wrong.
Thank you both so much for your help! I'll try these methods right away!
Edit:
SUCCESS!!
Thank you both a ton! I couldn't have figured this out without your help! <3
Edit:
SUCCESS!!
Thank you both a ton! I couldn't have figured this out without your help! <3
JavaScript:
$gameParty._items.length + $gameParty._weapons.length + $gameParty._armors.length
Or, y'know...
Code:
$gameParty.allItems().length
@Solar_Flare @Trihan - it's not the length the OP is after. It's the sum of the quantities of each item.
Something like this (untested):
assuming item is what's in each array element (the number held by the party).
I don't think this would include equipped items either.
Something like this (untested):
Code:
$gameParty._items.concat($gameParty._weapons.concat($gameParty._armors)).reduce(function (r, item) {return r + item}, 0);
assuming item is what's in each array element (the number held by the party).
I don't think this would include equipped items either.
Ahh, sorry. I missed the OP's ask, I was just going by what Solar_Flare posted.
is what you want, then.
Code:
$gameParty.allItems().reduce((r, item) => r + $gameParty.numItems(item), 0);
Original thread: https://forums.rpgmakerweb.com/threads/solved-get-number-of-items-in-inventory.124613/
