Shops and Chests with Random/Dynamic Items (similar to Binding of Isaac)

Hello there. I am planning a new project which relies a lot on randomness. I would like for chests and shops to contain/sell items choosen at random. However, not all items are available from the start, some need to be unlocked via various ways. The system is somewhat similar to The Binding of Isaac, where you unlock more and more items that can be found/bought the more of the game you play. I also have an idea how it could be done, but I can't do it myself.


Now for specifics:


For this example, assume the game has a total of 20 different items from various categories (potions, equipment, useable items like bombs or gas, maybe stat booster, etc). At the beginning of the game, 10 of these items are unlocked. The other 10 can be unlocked over the course of the game, by defeating a specific boss, opening a certain number of chests, completing a specific quest and so on. So, at the beginning shops would only sell items randomly choosen from these 10 unlocked items and in chests you can only find items from these 10 unlocked items. However, once you unlocked a certain item, it should be able to appear in the shop and in chests. Since you don't always unlock the same items at the same time (maybe you open 5 chests first and then defeat the boss, or maybe you defeat the boss first and then unlock 5 chests) it needs to be somewhat dynamic.


Specific for chests:


There are different types of chests. For example, one chests only contains potions. Another one only contains weapons. A third one can obtain any item. 


Specific for shops:


At the beginning of the game, shops sell 3 different items. However, later the player can unlock that shops sell 4 items, or 5, or 6 or whatever number. Also, at least one item will always be a potion, another always a weapon, the third completly random (but this is not that important, it would however be nice if it could be implemented, that certain items are guaranteed, or a guaranteed category).


How it could be done:


Each unlocked item gets a specific variable or switch (for example via notetags in the database). If this variable is anything else than 0, the item is eligible to appear in the shop/chest. If it's a switch, if it's on it can appear. So basically, at the beginning of the game you manually change the variables for unlocked items from 0 to anything else and these appear. If a new items gets unlocked, it's variable gets changed. As for the script, maybe it could look at each variable in a certain range, for example from 10-X (whatever X may be, 100 for example). And shops/chests only have items available which are part of these variable range.


So, that's my request and my idea. I haven't started the game yet, because if this doesn't work or I don't get a script I have to think how I could change the game accordingly.

Original thread: https://forums.rpgmakerweb.com/threads/shops-and-chests-with-random-dynamic-items-similar-to-binding-of-isaac.55600/