MV (BO_CustomShops) Randomized Shop with Limited Stock?

Hello! I'm using BurningOrca's Custom Shops plugin (link) and I wonder if it would be possible to make the items in stock depend on game variables, or otherwise find a way to set up a shop with randomly selected goods that are limited in stock.

For example, if $gameVariables.value(41) is equal to 22, then the first item in the shop is item 22. If the variable's value is 23 instead, then it's item 23, etc.
The core idea is to make a shop with a random selection of items that you can only purchase one of each.

I found a script to set up a random shop, but it only sets up a basic shop with unlimited item stock.
This is the script. It works well with the basic shop, but I'd like to add a stock limit of 1 to the randomly generated items.

I also messed around with a code that assigns random unique values to three variables, hoping that simply typing
$gameVariables.value(41)
into the item ID field would work, but I tried it now and it crashes the game instantly, so clearly that doesn't work.
it should work and you can set a limit stock per item ID and make the re-stock
to false, or manually to add it or when x time passes by.

everything is in the helpfile, and if that option isn't there for variables, you can
do so with the BO_CustomShopXL which has also experimental features.

you can set a notetag if it allows eval with, but other times to allow the itemID,
it needs to be set in the event first, like $gameVariable.value(41) = itemID.

than you can use that ID to call and set that into the parameter to call it to change
the ID to show, but it would require a combi (event and parameter) as event tells
which ID and which variable allow for stock which goes to -1 per item ID bought.

it might be possible to add a conditional below the shop to check that which can
be found on the forum how to do so.
I looked in the help section of the XL plugin, but unless I overlooked something, it doesn't seem to mention variables for anything other than custom currencies. I tried putting $gameVariables.value(41) into the item ID field like so, but it crashes the game instantly as soon as I start the playtest.
Spoiler
ex.png

I'm sure there's another way to set it up, but my limited java knowledge holds me back.
it doesn't have an eval for item name or ID, so it could be altered to do so.
I cannot find the other post that want to to use variables ID that was set
inside an event and calling the shop after that.

it might bave the approach you look for, else there is a condition for it to
set inside the parameter, but I think it is in the XL which has "note" to place
JS code inside of it.

but this require JS knowledge, but cannot recall if it has that for items too or
only on the switches, because I didn't use the plugin for a while while working
on something else, so I cannot really direct help you with the issue at this point.
No worries! Thanks anyway! I'll try to figure out something in the meantime. 👋
Temporarily, I made a randomized shop by putting all the possible shop items in a shop, and giving each item an availability condition that checks for the values of certain variables.

Before running the shop, I run the following script:
JavaScript:
var min = 1;
var max = 5;
do {
  var1 = Math.floor(Math.random() * (max - min + 1)) + min;
  var2 = Math.floor(Math.random() * (max - min + 1)) + min;
  var3 = Math.floor(Math.random() * (max - min + 1)) + min;
} while (var1 === var2 || var1 === var3 || var2 === var3);
$gameVariables.setValue(41, var1);
$gameVariables.setValue(42, var2);
$gameVariables.setValue(43, var3);
This assigns a random unique number from 1 to 5 to variables 41, 42, and 43. the min and max variables and the game variables' IDs can be changed to suit the shop's needs.
After randomizing the variables, I would also use, for good measure, the plugin command
RefillShopStock <name>
to make sure that the shop's stock is refilled. In my case, since i named the shop "test", the plugin command reads "RefillShopStock test".
Then, I use the plugin command to open the shop
OpenShop <name>
In my case, since i named the shop "test", the plugin command reads "OpenShop test".
Inside the shop, I have 5 items (corresponding to the numbers 1 to 5). Each item has an Availability Condition that checks for the value of variables 41, 42, and 43, to check if any of those variables has a value equal to a number from 1 to 5 (depending on the item).
For example, the first item's Availability Condition is:
JavaScript:
$gameVariables.value(41) == 1 || $gameVariables.value(42) == 1 || $gameVariables.value(43) == 1;
This checks if variable 41, 42, or 43 is equal to 1. If true, then that item is available.
This results in 3 out of 5 of the shop's items being available.

This is far from an ideal solution, especially as the number of possible random items and the number of game variables used increases, but it's something! And at least it works!

If anyone knows or finds out another method to create randomized shops, feel free to chime in! 👋
if you want to randomise 3 variables, than do that in a condition before opening
the shop with a switch (name it "test switch")

Code:
if: testswitch = OFF
control variables 41 = 1..5
control variables 42 = 1..5
control variables 43 = 1..5
RefillShopStock <name>
control switches test = ON
else
//nothing happens here
end
"open shop here"

when the switch is ON, nothing happens, ideal if they cancel out and reopen to
refill the stock again, so they keep the current stock.

you can refill the stock when the switch is OFF, on transfer to a different map or
during day/night system to check this so each day, turn the switch OFF.
so it restock again.
it require more checks if you want to check if the variable = out of stock before
it can be refilled as a stock of 4 and refill again, can be 2 so it wont match!
another way for restock is to use += 1...3 to "add" 1-3 items on current stock.

but that depends how you use the value on the current item if they checked first.
this might be a bit cleaner, but thats totally up to you.

Original thread: https://forums.rpgmakerweb.com/threads/bo_customshops-randomized-shop-with-limited-stock.161094/