Checking inventory items via script

Hi Guys!

I tried to search for what I wanted, but I don't see a topic about it anywhere so I'm hoping that I'm asking something relevant and new here.

Does anyone know where I can find a good explanation of how to check the player's inventory? I want to basically only allow certain events to happen if the player has 3 specific items of specific quantities in their pack, and I don't want to nest a ton of forks to do so.

Help would be much appreciated, and I apologize if I somehow missed what I needed and this thread is a repost of an older one.

Edit: I am an idiot and forgot the most important part of my question - I meant via script inside a single conditional fork. I don't know how to access the data that VX Ace uses to store its inventory quantities or anything. More on this in my second post >_<
You can use a Control Variables to set a variable to the quantity of some item in inventory (via Game Data). Then use it in a conditional branch to see if the variable is equal to or greater than the number required.

If you only want to do something if they have a particular number of 3 different items, you'll use 3 nested branches, with a default "you don't have the correct items" message if any of the tests fail. That could look something like this:

Code:
Change Variables [0001: qty] = Item A in InventoryConditional Branch: Variable [0001: qty] >= 5  Change Variables [0001: qty] = Item B in Inventory  Conditional Branch: Variable [0001: qty] >= 2    Change Variables [0001: qty] = Item C in Inventory    Conditional Branch: Variable [0001: qty] >= 4      Comment: If we get to here, the player has the correct quantity of all 3 items             : So remove 5 of item A, 2 of item B, 4 of item C and do whatever else             : is to be done when they have acquired the items      Comment: THEN, add a Jump to Label or Exit Event Processing so the "fail"             : stuff doesn't happen      Jump to Label: CheckDone    Branch End  Branch EndBranch EndComment: If we reach this bit, then it means one of the conditions above failed,       : so the player needs more of at least one item.Show Text: You need 5 of item A, 2 of item B and 4 of item CComment: If you want more of a conversation after checking, whether the player       : had the right item quantities or not, add them here, after a label       : (and use a Jump to Label in the 'true' condition above, instead of       : an Exit Event Processing)Label: CheckDone...
You can use a Control Variables to set a variable to the quantity of some item in inventory (via Game Data). Then use it in a conditional branch to see if the variable is equal to or greater than the number required.

If you only want to do something if they have a particular number of 3 different items, you'll use 3 nested branches, with a default "you don't have the correct items" message if any of the tests fail.
Thanks for the response! I just realized that I completely forgot to mention "via script in a single conditional branch" as part of my first post. Let me try this again.

Is it possible to get a quantity of a certain type of item in the inventory via script? (As in declare a variable in the script, run some query to find the item amount and store it in that variable)

My grand plan was basically to do something like (pseudocode):

if [item_quantity_1] > 3 && [item_quantity_2] > 1 && [etc] then return true...as part of a single conditional fork, since you can use scripts to do the conditional part. I've done plenty of programming/scripting, but never used Ruby or VX Ace before, so I can't figure out where all the data I want to access is stored, or which commands to call to get to it.

I apologize for not being clear... I was so busy confusing myself with scripts that I didn't even mention the most important part!
Yeah.


You leave out the if because that's implicit in the Conditional Branch.

Code:
$game_party.item_number($data_items[id1]) >= 3 && $game_party.item_number($data_items[id2]) >= 1 && $game_party.item_number($data_items[id3]) >= 5
Thank you again!
 
As a side note, in case anyone else wants to use the above script for anything, be aware that I had to remove the "id" part of "$data_items[id<whatever>]" in order to get it to work.
e.g.

Code:
$data_items[20]
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
As a side note, in case anyone else wants to use the above script for anything, be aware that I had to remove the "id" part of "$data_items[id<whatever>]" in order to get it to work.
I did not mean for you to actually include 'id' in the command. I used id1, id2, id3 to indicate the id of each individual item (ie - id of item 1, id of item 2, etc) 🙂

Original thread: https://forums.rpgmakerweb.com/threads/checking-inventory-items-via-script.19793/