What I'm wanting to do is create a conditional branch that that will hand a player an item if they have space for it (in my case, 10 inventory slots). If they don't have space, then it will play the else branch (for example: "you don't have enough space"). I tried using variables by having the player add to a specific variable when they pick up an item but I came across the problem of not being able to add/subtract the variable during a shop, yanfly's item discard, and enemy loot or even when using the item. I'm also wanting to apply this to weapons and armors. If there is anyway around this issue I would appreciate it very much.
MV How to make a conditional branch for overall item count?
RPG Maker MV SupportYou can do this without any plugins or scripts, but you'll need to use a variable.
Create a Control Variables command. Click on Game Data -> Item and select the item from the list. Then, create a Conditional Branch that checks that item. This works for armors and weapons as well (there are separate options for each).
If for some reason you really want to avoid using a variable, you can also use a Conditional Branch with this script call:
Replace 123 with the database ID of the item. For weapons or armors, just write
EDIT: The above is assuming you want to check how many of that specific item the party has. If you want to check the total number of items the party has, you can still do it with a script call, something like the following:
That's untested, so there might be some small errors in it. You could take the same approach even with basic eventing, but it would be tedious – I think you'd need to add a Control Variables for every single item to add them all up, and then the Conditional Branch.
Create a Control Variables command. Click on Game Data -> Item and select the item from the list. Then, create a Conditional Branch that checks that item. This works for armors and weapons as well (there are separate options for each).
If for some reason you really want to avoid using a variable, you can also use a Conditional Branch with this script call:
JavaScript:
$gameParty.numItems($dataItems[123]) < 10
Replace 123 with the database ID of the item. For weapons or armors, just write
$dataWeapons or $dataArmors in place of $dataItems.EDIT: The above is assuming you want to check how many of that specific item the party has. If you want to check the total number of items the party has, you can still do it with a script call, something like the following:
JavaScript:
$dataItems.reduce((prev, next) => prev + (next ? $gameParty.numItems(next) : 0), 0) < 10
That's untested, so there might be some small errors in it. You could take the same approach even with basic eventing, but it would be tedious – I think you'd need to add a Control Variables for every single item to add them all up, and then the Conditional Branch.
This works perfectly for the conditional branch.
Is there any way this could apply to shops and enemy loot? For example, if I try to buy an item when all 10 of my inventory slots are full, could it activate an event or something else that could prevent me from buying?(like a text box that says "your inventory is too full to buy anything") and for enemy loot, if my inventory is full and I gained an item, could it activate an event or something that could let me discard an item or leave the enemy loot?
Ah, if you want to prevent them from buying items when they already have 10 things, I think you'll need a plugin. Similarly if you want something that triggers when you get an item drop from battle. These are definitely both possible.
I have had luck using Yanfly's ShopMenuCore along with the ItemCore regarding the issue for shops. All I had to do is set the maximum number for items/weapons/armors and it won't let me purchase items until I make space(as intended). But I'm still looking for a solution for the boss drops. I'll create a separate thread for that so I don't go off topic.
I should have mentioned this earlier. Is there a way to change this for armors and weapons. I had tried changing $dataItems to $dataWeapons but it didn't seem to work. Is there anything else that needs to be changed for it to work?
I'm pretty sure just that change is sufficient. What went wrong when you tried it?
You're right, it was an error on my end. I tried to put =0 and it didn't work but <=0 or <1 works fine.
When youre using the script boxes, youre using javascript. You would want to use === 0 to check if your item check resulted in 0. = 0 means something else
Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-conditional-branch-for-overall-item-count.178539/