Random shop

So I am sure many of you have played disgaea and maybe other games that when you go into a shop the inventory they have is randomized. Generally the items are based on either your main characters level or the level of the shop that increases as you progress or spend more money. I'm curious since rmmv runs off of javascript if it would be possible to make a script that has a variable linked to every item. This would have to be done manually of course but when you open the shop it can pull a random number say between 1-10 for the variable that is linked to "swords" for example and only show 1 sword between those variables. I have been playing with this for a few days now but I cannot figure out how to make those calls. When you pick the sword it would to buy it you would get that sword for the price of that sword and that item would disappear from the item shop. The next time you open the shop the inventory would be randomized again and you would see a different selection of swords, axes, bows etc.

Open shop -> choose weapons -> scroll through list of randomized weapon choices -> buy weapon -> close shop -> randomize shop inventory again -> open shop -> repeat.

Maybe I misunderstood the scripts that the core files use but I couldn't find much info on those specific commands on my own.
You can randomize a shop by building an array of item data, structured like so:

Code:
var goods =
[
  [itemType, itemId, isCustomPrice, customPrice],
  ...etc
]
// itemType: 0 = items, 1 = weapons, = 2 armors
// itemId:  this is the id of the item/weapon/armor
// isCustomPrice: 0 = use default price, 1 = custom price
// customPrice: the custom price for this item, if applicable

A sample list of goods might look like this:

Code:
var goods =
[
  [0, 1, 0, 0], // the first item, default price
  [1, 5, 0, 0], // the 5th weapon, default price
  [2, 22, 1, 256] // the 22nd armor, custom cost of 256
]

// then, to invoke a custom shop using the above list:

SceneManager.push(Scene_Shop);
SceneManager.prepareNextScene(goods, false);

// if you want the shop to be buy-only, change the false to true

That said, this kind of reminded me about the 95% finished custom/dynamic/limited quantity shop plugin I started several months ago, but forgot to finish. Maybe I'll go do that now. 🙂

Anyway, hopefully this helps!
Moved to: JS Plugin Requests

Original thread: https://forums.rpgmakerweb.com/threads/random-shop.116988/