Hi folks,
My game is a farming game, and has crop items with multiple quality levels (like Stardew Valley). Each crop of a different quality is a different item in the database with a unique item ID, the same name, and a different sell price.
I have an NPC that asks the player to give them X of a certain crop (of which there are many possible kinds). I want to remove X of items with the matching name from the players inventory, in any combination of qualities (item IDs).
I keep over-complicating this in my head when I try to think through an efficient way to do this (such as setting a variable to the item name (string), cycling through the player's entire inventory, checking names of each item they have, and incrementing a variable each time to track quantity. Then, if the variable is high enough to pay the price, cycling through again to take the items with a matching name one at a time starting with the lowest quality while incrementing a second variable, and stopping when the variables match).
Before I waste a lot of time trying to make something work, do any of you RPG Maker wizards have a better idea?
In short, the process needs to be something like:
If the player has X or more of items named Y, remove items named Y, starting with the lowest item ID until X are removed.
Any help is much appreciated!
My game is a farming game, and has crop items with multiple quality levels (like Stardew Valley). Each crop of a different quality is a different item in the database with a unique item ID, the same name, and a different sell price.
I have an NPC that asks the player to give them X of a certain crop (of which there are many possible kinds). I want to remove X of items with the matching name from the players inventory, in any combination of qualities (item IDs).
I keep over-complicating this in my head when I try to think through an efficient way to do this (such as setting a variable to the item name (string), cycling through the player's entire inventory, checking names of each item they have, and incrementing a variable each time to track quantity. Then, if the variable is high enough to pay the price, cycling through again to take the items with a matching name one at a time starting with the lowest quality while incrementing a second variable, and stopping when the variables match).
Before I waste a lot of time trying to make something work, do any of you RPG Maker wizards have a better idea?
In short, the process needs to be something like:
If the player has X or more of items named Y, remove items named Y, starting with the lowest item ID until X are removed.
Any help is much appreciated!