Item quantity

Any idea how to set the quantity of an item?


Isee option add and remove, but I did't see set exact quantity.
Yes just set a variable and name it what you like.


8c72136a4e9ceffc875877f807305bc6.png



Go to control variables and set it to the quantity you want to give the player.


7c1d68eeb74abb731c75ad190351dd47.png



a7daf8b4a9feb3a22c8f3287e3e2d2d5.png



Go to change items and set it to the variable you made earlier.


98323538bf56b615d2a587147d04e9bc.png



912384d4ecc9b6b69e6f56f1c572c959.png
Game_Party.prototype.setItemQuantity = function(item, amount) {
var container = this.itemContainer(item);
if (container) {
container[item.id] = amount.clamp(0, this.maxItems(item));
if (container[item.id] === 0) {
delete container[item.id];
}
$gameMap.requestRefresh();
}
};


Copy that script to the rpg_objects.js in Game_Party section or any place below this,


function Game_Party() {
this.initialize.apply(this, arguments);
}


How to use:


Script Call,

Code:
/* Item
   $dataItems[id] or $dataWeapons[id] or $dataArmors[id]
*/
$gameParty.setItemQuantity(item, amount);
ok yes, I know this method... But I don't want tu use varable for many reason...


It's a good way but in my case I want to do it by a script if possible.


By the way, your method have a "hic", I want to set to 0 the quantity, So using your method wil force me


to put existing quandtity in a variable and after removing this quantity to the existing quantity.
@XGuarden you could do exactly what Silenity said, but with script calls.


Just remove 99 of the object: You now have 0 of the object.


Then add the desired quantity: You now have [quantity] of the object.


Congratulations: You have "set" the item quantity to the [quantity].


This works just fine:


$gameParty.gainItem($dataItems[itemId], -99);
$gameParty.gainItem($dataItems[itemId], your_quantity);




I didn't test @Kadafi's solutions, I'm sure it would work but it's likely a bit overkill for something so simple. Unless there's something I'm missing.


Edit: Below is the way to directly influence item quantity.


I'm providing it because that's what you're asking for, but you shouldn't mess with it: referencing objects the party doesn't have or inputting something that isn't a number as a quantity will likely bug your game.


Using the way I described above is much safer.


$gameParty._items["your_item_id"] = your_quantity


You can access weapons and armors too if you want.
I will test your solution, I  don't know that rpg maker can't go under 0 off quantity, if that the case your solution will work just fine in this case.


Of course, for setting another quantity then 0, we can just minus 99 and add quantity after. Let me test...I will mark you as best answer if work.

Original thread: https://forums.rpgmakerweb.com/threads/item-quantity.64554/