RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[MV] Randomized Shop Inventory

0 Members and 1 Guest are viewing this topic.

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Best RPG Maker User - Creativity2014 Kindest Member2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Randomized Shop Inventory

Want your shopkeepers to sell something different every now and then? This snippet script call will let you randomize your shopkeeper's inventory!

I made this little code snippet for my game because I'm working with a time system and wanted to have the shopkeepers randomize their goods daily. It's short and sweet, so all you have to do is copy paste it into a script command and then change the values on the first line to fit your needs. :)


Step 1 - Randomization Code:
Paste the following code as a script call on the event that will randomize the shop's inventory.

Code: [Select]
var id = 0, type = 0, min = 0, max = 0, inv = 0;

var array = [], temp = [], rand;
for(i = 0; i < inv; i++) {
do { rand = Math.floor(Math.random()*(max-min+1)+min);
} while (temp.indexOf(rand) > -1);
temp[i] = rand;
array[i] = [type, rand, 0];
}
if(Array.isArray($gameVariables.value(id)))
   var array = $gameVariables.value(id).concat(array);
$gameVariables.setValue(id, array);

ONLY change the first line of code. Replace the "0"s with the following information:

id = the variable id that you want to store your randomized shop data in
type = the type of shop items you want to randomize (0 = items, 1 = weapons, 2 = armor)
min & max = the minimum and maximum item ids to work with (i.e. min = 4, max = 20 will pick any items between 4 and 20)
inv = the number of shop inventory items you want to be randomized and added

Example:

Code: [Select]
var id = 61, type = 0, min = 16, max = 127, inv = 10;

The above example randomizes 10 items from between ID 16 and ID 127 and stores the info in variable 61.

Step 2 - Calling the Shop Processing:
After you have ran the code to randomize your shop's inventory, you will need to use a script call to summon the shop processing using the variable you stored the information in. This is how it's done:

Code: [Select]
goods = $gameVariables.value(0);
SceneManager.push(Scene_Shop);
SceneManager.prepareNextScene(goods, true);

All you have to do is change the first line and change the "0" to whatever variable you have used.



Examples & Information:
Spoiler for Screenshot:

(The second script call has a different order of variables. I changed them and forgot to update that one. Oops!)

Resetting the variable
On the very first line in the screenshot, I manually reset the variable to = 0 to erase any previous data in it. This is because the randomized shop items WILL stack when you call the code again unless you remember to reset it.

Mixed Item Shops:
The reason I set up randomized items to stack was for the purpose of having mixed types of shops. Basically, having a shop where the vendor can sell items, weapons, and armor at the same time. For mixed items in a shop, simply copy and paste the code another time and edit it. For example (as seen in the screenshot), my first script call randomizes 10 items, whereas my second script call randomizes 2 weapon types.

And after that, all that's left to do is use the shop processing script call! I don't recommend doing this in the same event (like I did in the example), because you don't want the shopkeeper to randomize his goods every time you talk to him. :p

And, that's all! ^-^
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


*
Rep: +0/-0Level 25
RMRK Junior
I have been searching the internet for something like this for days, and was so excited to use it, but I'm getting "Type Error: Cannot read property 'setupGoods' as null"

I'm not sure what that means or what I'm doing wrong. Is there anything you can do to help?

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Best RPG Maker User - Creativity2014 Kindest Member2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Sure, I can take a look! :)

Can you provide a screenshot of your script calls? My guess is that some crucial variable is not set-up properly and is defaulting to "null".
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]