How to Random Loot Quickly

Hi all,

I have a fairly complete database of weapons, armors, and items. I am using Yanfly's augment plugin to add sockets to armors and weapons which considerably increases both weapons and armors. I am looking for a fast and easy way to generate random loot. I think I would like this to be in the form of a common event so it can be used easily.

I have three variables so far :

1) Variable #99 named "Loot Type" which chooses between weapon, armor, or item. This could be increased to add gold as a random option but I have no clue how to award gold as a random number.

2) Variable #98 named "Sockets (Yes or No)" which will allow the items to be chosen from the socket list or the non socket list.

3) Variable #100 named "Loot Roller" which selects the rolled items ID. Socketed Weapons: 109-227, Non Socketed weapons 2-33, and 91. Socketed Armor: 112-240, Non Socketed 1-31 and 52-69, 90, 105-107, and 110. Items: 1-21, 43-48, 90-100.

Unfortunately I have hundreds of items and an event of this magnitude will most likely have errors on my part. I would like to hear some options from the community. How do you all go about random loot? So far I only have eventing experience and even variables are relatively new to me. The thought of eventing something like using conditional branches makes me cringe. I'm looking forward to everyone's opinions and helpful advice. Thanks in advance.
I think it would be fairly easy to do, but the problem you haven't discussed is how to avoid giving the player an end-game type of item when they're just starting. If you were to add gold, would you want a player who was 10 minutes into the game getting 10,000 gold?

You could actually do all of that using just one variable.
@Shaz thanks for your quick reply. I excluded quest items and boss loot from the random roll. That's one reason there is some gaps in my database as far as IDs are concerned. If gold was chosen it could be a minor problem but honestly my game is small and everything is centered around one hub town. I would personally keep the gold amounts small, as the purchase price of items, weapons and armor are very low in my game compared to others. Also that is if I chose to use gold which I am not sure I want to for the same reason you mentioned. I would also be careful with the placement of chests, and even thought about the player finding lock boxes that have been magically sealed and need a mage to open them, the mage then wants a fee to open the lock box. I am however more concerned with how other people have implemented random loot into their games and how they did it? Thanks for your reply and I did not know I could use just one variable thanks for that info.
Script lines are your friend here.

To gain an Item, Weapon, or Armor, the script line is: $gameParty.gainItem(loot, quantity, include_equip);

loot is the thing that the player will receive, for example $dataWeapons[12] for Weapon ID #12 in your database. $dataItems[n] and $dataArmors[n] are how you would reference Items or Armors instead, with n being the ID in your database.

quantity is the number of that thing you'll gain, usually 1.

include_equip is mostly used for when weapons or armor are being removed from the party's inventory and therefore is irrelevant to your purpose, so just set it to false.

Therefore, instead of having a hundred different branches of your code based on a random variable roll, you can do something like roll 1-5, and if the result is 1-3, you give the player a random item, 4 a random weapon, 5 a random armor. Then roll a second time, 1-50 or whatever. Plug the result of that roll as "n" into $dataItems[n] to give the player a random item. The value of a Variable can be fetched using the code $gameVariables.value(x). For example, if you've decided to give the player an item and you use Variable #108 to roll the Item the player is getting, the script line would be:

$gameParty.gainItem($dataItems[$gameVariables.value(108)], 1, false);

This looks terribly complex, but the good news is that this one line substitutes for ALL of the conditional branches you'd need to give the player different random items.

You can balance this system better by having different "tiers" of battle difficulty in your game (designated based on the area where the chest is found, or some other criterion), and equate those with "tiers" of items you can receive from chests. Arrange the items/weapons/armors in your database accordingly, for example 1 is the weakest item (a simple potion, a wooden sword) and 50 is the strongest item (a party-wide full heal elixir, Excalibur). In the treasure event, first designate the tier to draw from, and then randomize the result within that tier. For example, if Tier 2 treasures should give you something with an ID from 20 to 39, then draw a random result from 20 to 39 (instead of from the full list of 1 to 50), and then plug that random selection into the script lines above, just like you would if it were a fully random selection from 1 to 50.
@Wavelength Thanks for your reply, It looks like script is definitely the way to go. I have no experience using script other than copy and pasting it into events. I understood some of what you said, I think. Instead of conditional branches in the event I would use one line of script for each time I would need to roll? Also do I need a separate variable for each line of script or can it be the same variable each time? I may need walked through this process a little further once I start working on this event, I hope that will be alright? I am sure more questions will arise.

Thank you for your time.

UPDATE: I started working on the event. This is what I have so far. Screenshots below.
For some games, I use a prefix/suffix plugin that allows random prefixes and suffixes on items. Then I use small stat gains for early weapons/armor, and larger ones for later ones. This works for certain types of games. For other types, I don't let random enemies drop weapons or armor. Either it's a boss, and I don't randomize what they drop, or it's a treasure chest, and I do a handful of random possibilities (by doing a random number as a variable and then whatever that number is determines the item).
@mobiusclimber I also have a random prefix and suffix plugin, courteous of DreamX but I want to give out random rewards from a list and then have random prefix and suffix added via the plugin. Also I am using Yanfly's augment plugin that allows socketed items from games like Diablo. I just needed a way to distribute these items to the player so the game can be played many times over and is a little different each time. Thanks for your input though.
I haven't used it, but Yanfly has a plugin to give enemies more random drops and set up conditions for certain random drops: http://yanfly.moe/2015/12/19/yep-47-extra-enemy-drops/

[edit: another thing you can do is have enemies drop treasure boxes that are items with a common event that randomizes the loot.]
@mobiusclimber That plugin could work but I would have to input notetags on all my enemies and create a list of hundreds of IDs to create the note tags. Even with copy and paste functions this does not sound fun. Thanks for the link though.

@Wavelength My event and script does not seem to be working. Can you steer me in the correct direction? I posted a couple of screenshots in a prior post. Any help will be appreciated.
EDIT : FIND IT ALONE WAZAA
For people who want to know how to put a message to know what item was dropped
the line to add to this script code is :

var reward = $dataArmors[$gameVariables.value(IDVariable)];
$gameMessage.add("Obtened " + reward.name + "!");

Hi Everyone,

I was also trying to find how to do a random chest with a script call because my game is based on that and my random chest goes between a huge amount of armors (Fom ID 29 to ID 220).

The script call is really good but the problem is that now the player don't really know what was in that chest.
I use Mog_Hunter TreasurePopup in my game but sadly it seems that it doesn't work with this script call...

Do you know how i can had a line for this Popup ? or if i have to add a message text which can say what the player have looted ?
(Then me too i am bad at coding so i really don't know how i can add a text with the name of this armor...)

Thanks in advance
EDIT : FIND IT ALONE WAZAA
For people who want to know how to put a message to know what item was dropped
the line to add to this script code is :

var reward = $dataArmors[$gameVariables.value(IDVariable)];
$gameMessage.add("Obtened " + reward.name + "!");

Is it possible to color code the text reward.name on the messagebox?

EDIT: It seems to work with automessagecolor plugin by Irina.
var reward = $dataArmors[$gameVariables.value(IDVariable)];
$gameMessage.add("Obtained \\c[x]" + reward.name + "\\c[0]!");

where x is the color in the pallet, 0 is the first color in the window pallet. check you window png file for color

Original thread: https://forums.rpgmakerweb.com/threads/how-to-random-loot-quickly.104863/