Checking inventory items via script

Status
Not open for further replies.

Perpetr8r

Villager
Member
Joined
Nov 9, 2013
Messages
6
Reaction score
0
First Language
English
Primarily Uses
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 >_<
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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...
 

Perpetr8r

Villager
Member
Joined
Nov 9, 2013
Messages
6
Reaction score
0
First Language
English
Primarily Uses
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!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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
 

Perpetr8r

Villager
Member
Joined
Nov 9, 2013
Messages
6
Reaction score
0
First Language
English
Primarily Uses
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]
 

Celianna

Tileset artist
Veteran
Joined
Mar 1, 2012
Messages
10,557
Reaction score
5,592
First Language
Dutch
Primarily Uses
RMMV
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.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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) :)
 
Last edited by a moderator:
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,040
Members
137,569
Latest member
Shtelsky
Top