Potion Shop Game - How to Make An NPC Ask for a Random Item

Ok, so I'm trying to make a game about selling potions. I have a single event that controls a few things which sort acts as the drop off point to give clients their potions. The problem is I want the type of potion this event/NPC wants to be random and I'm having trouble understanding how to do I get this event to assign an item the event wants dynamically AND sell said item it wants.

I think I got code that's almost there. Basically I got a common event that uses 4 variables in it

License Level - Determines how high the Array will roll for "Potion Type"
#22 Potion Type - Determined by RNG set to a number
#23 Potion Request - Changes value to number of assigned item
#24 Potion Name - Uses script to pull items name for NPC to say

So if I have the event subtract from "Potion Request," would that work and/or sell the item?

1761010112579.png
Create a variable that draws from a range of possible numbers:
1761011250884.png


Then create a Conditional Branch for each of the possible items:
Code:
◆Control Variables:#0032 = Random 1..5
◆If:#0032 = 1
  ◆
:End
◆If:#0032 = 2
  ◆
:End
◆If:#0032 = 3
  ◆
:End
◆If:#0032 = 4
  ◆
:End
◆If:#0032 = 5
  ◆
:End

Of course this can be simplified with Javascript through Arrays as you could more easily create rarely purchased items or very common items without creating countless conditions.
and your last control variable about the potion name is a problem:

the setvalue command is double, since it is already inside the control variable command, and it always gives the name of the item ID 2.

correct would be something like (untested, I hope I didn't make an error):

$dataItems[$gameVariables(22)].name

Original thread: https://forums.rpgmakerweb.com/threads/potion-shop-game-how-to-make-an-npc-ask-for-a-random-item.180641/