Random Loot


Astfgl's Random loot
​
Hi everyone! This simple plugin was made to handle random loot and its display.

I've seen the request for such a system pop up a few times and, although this can be evented to a certain degree, I thought a plugin could help.

Features:
  • From user defined loot tables, give random loot.
  • Use items as bags of loot via notetags, without using a common event.
  • Handles weapons, armors, items and gold.
  • Use the parameters to automate the item gain message via variables.
  • V1.2: Trigger monster encounters. Only tested on the map screen. Use at your own risk for items in menu or during battle.
  • V1.2: Return the loot table, deleting the item the player just got. This allows you to remove randomly gained items from the loot table so that your player doesn't get the same possibility twice from the same loot table. You'll have to store the loot table in a variable beforehand.
  • V1.3: Loot bags are now purchasable and can instantly open upon purchase, just add <LTPurchase> to your item.
  • V1.4: Items can now have several loot tables, just add more loot tables like this: <lootTable:>, <lootTable2:>, <lootTable3:>,... Please note that the variables defined in parameters will only contain info for the last obtained item.
  • V1.5: Loot tables can now roll for other loot tables

Download:


Terms of use: Find them in the plugin file for reference. Pasted below:

Code:
// Free to use both commercially and non commercially.
// Edits allowed, but the product must be released with the same license.
// Credits required: any of Astfgl/Pierre MATEO/Pierre MATEO (Astfgl)
// Reposts allowed.

Setup:
  • Download the plugin, name the file AstfglLT save it as a .js .
  • Setup parameters as you see fit.
Usage: Refer to the plugin's help file.

Example:
Spoiler
Excuse the MS Paint editing:
NUcfoH6.png

Known Bugs:
  • None
Credits:
  • Astfgl66
awesome, this is really helpful with my current project
It's been a while since I last posted in that thread, but there has been multiple updates now. You can find the updated feature list in the original post.

I'm posting now to let users know that a bug introduced in 1.4 that prevented items to be consumed upon use is fixed.
Thanks to @Allerka for catching it and sending a bug report!

Have a nice day, and happy making!
EDIT* easier question

can this plugin call a plugin command instead of delivering an item?
Unless I misunderstood something, just call for random loot three times: first on the normal, then on the uncommon and finally on the rare loot table.

Loot tables are just arrays, so if you want to make an array from selected elements of a loot table, you'll have to do a bit of array manipulation. It's very simple javascript that a bit of googleing will solve.

If you are unable: just do it by hand.
My apologies for not explaining myself.

Basically instead of having a single item as a table item, i want to have a rarity, then if I get that rarity get a random item from that array.

ex: <lootTable:[[1,common,1,100],[1,uncommon,1,70],[1,rare,1,30],[3,superrare,1,5]>

So lets say I script on common event

var common = [0, 1, 2]
$gameVariables.setValue(0001, common);

var uncommon = [3, 4, 5]
$gameVariables.setValue(0002, uncommon);

How do I integrate it ? will this work?

$gameMap.loot([[2,$gameVariables.value(0001),100, ],[2,$gameVariables.value(0002),1,20]])

If so, how can I make it so it will only give me 1 item and not the full array?
Okay, that wasn't possible, but it was an easy addition.
I've made an update to the plugin, allowing for what you asked.

So following your example, you'd do:
Code:
var common = lootTable1;
var rare = lootTable2;
var legendary = lootTable3;
var lootTable = [[5,common,0,75],[5,rare,0,20],[5,legendary,0,5]]
$gameMap.loot(lootTable)

For a 75% chance to roll on the common loot table, 20% for a rare roll, and 5% for a legendary roll.

By the way: no leading zeros on numbers: $gameVariables.value(1) and not 0001.
holly crap this is amazing thank you!
I got some difficulties understand it correctly on the loot tables:

structure is:
[itemType, itemId, quantity, probability]

$gameMap.loot([[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]])
so each table has 30% chance

$gameMap.loot([[0,1,1,90],[1,1,1,10],[2,1,1,5],[3,0,500,2]])
loot change so far I understand: 90%, 10%, 5%, 2% (so far I get it)
so you have bad luck if it rolls a big number at start (so it wont be actual % way)

2 things I dont really get:

var common = lootTable1;
var rare = lootTable2;
var legendary = lootTable3;
var lootTable = [[5,common,0,75],[5,rare,0,20],[5,legendary,0,5]]
$gameMap.loot(lootTable)

in your exsample, how does this plays out.

like:
var common = [0,1,1,50];
var rare = [1,1,1,35];
var legendary = [2,2,1,15];
var lootTable = [[5,common,0,75],[5,rare,0,20],[5,legendary,0,5]]
$gameMap.loot(lootTable)

or as actual numbers?

lastly:

4 -> Monster [4, encounterId, canEscape, probability, canLose]

which there is no example:
so [4, 3,false, 20, false]? (false or true) or numbers 1 (true), 0 (false)?

I want to see if I can re-construct the helpfile for my own to understand
the plugin fully.
@ShadowDragon I'm having a hard time following your reasoning which I suspect is because of the language barrier, so I'll go over it step by step to make it hopefully clearer.

Code:
$gameMap.loot([[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]])
so each table has 30% chance

No, each table has an equal chance of being picked, which is 25%.

Code:
$gameMap.loot([[0,1,1,90],[1,1,1,10],[2,1,1,5],[3,0,500,2]])
loot change so far I understand: 90%, 10%, 5%, 2% (so far I get it)
so you have bad luck if it rolls a big number at start (so it wont be actual % way)

From these two things I gather you don't understand how rolling works in my plugin:

1-First the plugin calculates the sum of all numbers you put in probabilities.
This means in the first case the sum would be 120 (30 * 4), and in the second case the sum is 107 (90+10+5+2).

2- The plugin rolls a random number between 1 and the sum so for the first example between 1 and 120 and the second example between 1 and 107.

3- The plugin then picks the reward based on which number it rolls, it goes through the reward array and picks the reward if it falls within 0+ the reward's probability.

Let's go with the first example: the plugin sums up the probabilities, gets 120, rolls between 1 and 120, gets 97.
1st reward is in range 1-30, not picked, 2nd reward is in range 31-60, not picked, second reward is in range 61-90, not picked, last reward is in range 91-120 , which contains 97. The plugin will hand out the last reward of the loot table.

For the second example the sum is 107, let's say that the random number the plugin rolls is 98.
1st reward is range 1-90, not picked, 2nd reward is range 91 - 100, 98 is in between 91 and 100 so the plugin will hand out the second reward.

The plugin will always hand out a reward. Though I guess if you wanted a chance at an empty box you could you make an item quantity = 0.

Code:
var common = [0,1,1,50];
var rare = [1,1,1,35];
var legendary = [2,2,1,15];
var lootTable = [[5,common,0,75],[5,rare,0,20],[5,legendary,0,5]]
$gameMap.loot(lootTable)

This won't work because the plugin expects loot tables here, not items. So something like
common = [[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]];

Code:
4 -> Monster [4, encounterId, canEscape, probability, canLose]
which there is no example:
so [4, 3,false, 20, false]?   (false or true) or numbers 1 (true), 0 (false)
It expects you to put in "false" or "true", without the quotes. Although given that this is javascript there's a high probability that 0 will be treated as false and 1 as true by the engine anyway.

So for example: [4,31,false,30,false].
than final question.

var common = [[1,1,1,50],[1,2,1,30],[1,3,1,25]];
var uncommon = [[3,1,1,36],[2,1,1,]];
var rare = [[2,1,1,10],[2,1,1,5]];
var lootTable = [[5,common,0,75],[5,rare,0,20],[5,legendary,0,5]]
$gameMap.loot(lootTable)

should work? (if its 2,3,4,5 loot tables)? or does it require a fix amount of 4?

so common if number is 66 rolls loot table "common"
than makes the sum of 50+30+25 (105) which than rolls a number and check
the 3 within it falls?

if so, than I can place that as example (also as a spoiler here to see if I got
everything correctly understanded so they may replace it or keep it save
to fully understand if they have trouble like I have, but I get the other parts
more on the loot tables.
@ShadowDragon Your example should work yes.

Code:
so common if number is 66 rolls loot table "common"
than makes the sum of 50+30+25 (105) which than rolls a number and check
the 3 within it falls?
Yes, in this example 66 is between 51 and 80 so item n°2 is picked.


Code:
should work? (if its 2,3,4,5 loot tables)? or does it require a fix amount of 4?
The plugin can roll for any amount of items or loot tables.
You could have 50 loot tables with 100 items each if you wanted. A loot table that rolls for other loot tables and items both should also work.
I alter the helpfile tomorrow and post it in a spoiler which might
help other better understanding if that is ok with you 🙂

Thank you for the explanation for understanding it more.
Sure. I'll even add it in the main post if I like it and you're okay with it.
here is mine version re-structed, in the hope it will be more clearly.
(for me at least what every function does and work (missing monster bags)

so I hope I didn't miss anything and everything correct.
spoiler contain the re-structed version.

you are free to add it to the main post or update the plugin, if nothing is missing.
but they can use it as alternate or next to the original helpfile.

again, thanks for some clarifications 🙂
Spoiler: Re-structed AstfgLT helpfile
JavaScript:
// Restructure Helpfile AstfglLT \\ <= by ShadowDragon (revised by Astfgl66)
/*
// <== BASE STRUCTURE USAGE ==> \\
Loot table structure:
[item1, item2,...,itemN]
Each item is defined this way [itemType, itemId, quantity, probability]

itemType:
0 -> Weapon
1 -> Armor
2 -> Item
3 -> Gold
4 -> Monster [4, encounterId, canEscape, probability, canLose]
5 -> Loot table [5,loot table, 0, probability]

itemId: the id of the item in the database;

quantity: how many of the item you wish to give

probability: the probability that particular item will be picked
in relation to the other items. Not a percentage, unless your sum
of probabilities for all items is = 100.

Loot tables can roll for other loot tables like in this structure:
    var common = lootTable1;
    var rare = lootTable2;
    var legendary = lootTable3;
    var lootTable = [[5,common,0,75],[5,rare,0,20],[5,legendary,0,5]]
    $gameMap.loot(lootTable)


Some examples of how they work.

Example 1:
$gameMap.loot([[0,3,1,30],[1,5,1,30],[2,12,3,30],[3,0,500,30]])

In this example, the loot table is composed of the following items:
Item 1: Item type 0 (Weapon), ItemID 3, quantity 1 and a probability of 30
Item 2: Item type 1 (Armor), ItemID 5, quantity 1 and a probability of 30
Item 3: Item type 2 (Item), ItemID 12, quantity 3 and a probability of 30
Item 4: Item type 3 (Gold), ItemID 0, quantity 500 and a probability of 30

Each probability is equal so the base chance for each item will be 25%.
Let's run through it:

First the plugin will sum all the probabilities (30 + 30 + 30 + 30 = 120 in this case).
Then it will generate a random number between 1 and the sum. (1 to 120 in this case)

Let's say we roll a 45.
It will then compare that number to the sum of probabilities step by step:

45 is > 0 but >= 30  so the first item is not picked.
45 is > 30 and <= 60 so it falls within the sum of probabilities
of the first two items: item 2 will be picked.
45 is not > 60 and <= 90 so it won't pick item 3;
45 is not > 90 and <= 120 so it won't pick item 4;

so it take item 2, which is an Armor type with ID 5.

If we rolled 100:
100 is > 90 and <= 120 so item 4 will be picked: which is Gold type and gain 500 gold.

Example 2:
$gameMap.loot([[0,1,0,30],[1,5,1,50],[2,12,3,20],[3,0,500,5]])

in this example, loot table is as followed:
Item 1 has: Item type 1 (Weapon), ItemID 1, quantity 0 and a probability of 30 (empty loot)
Item 2 has: Item type 1 (Armor), ItemID 5, quantity 1 and a probability of 50
Item 3 has: Item type 2 (Item), ItemID 12, quantity 3 and a probability of 20
Item 4 has: Item type 3 (Gold), ItemID 0, quantity 500 and a probability of 5

First the plugin will sum all the probabilities (105 in this case)
Then it will generate a random number between 1 and the sum. (1 to 105 in this case)

Let's say we roll a 51.
It will compare that number to the sum of probabilities:

51 is > 0 but >= 30  so the first item will not be picked.
51 is > 30 and <= 80 so it falls within the sum of probabilities
of the first two items: item 2 will be picked.
51 is not > 80 and <= 100 so it won't pick loot item 3;
51 is not > 100 and <= 105 so it won't pick loot item 4;

In the end, ittem 2 is picked, which is an Armor type with ID 5.

If we rolled 99:
99 is > 80 and <= 100 so item 3 will be picked: which is an Item type with ID 12.

Example 3: Monster bags
$gameMap.loot([[4,31,false,60,false],[4,37,true,30,false],[4,44,false,10,true]])

in this example, loot table is as followed:
Item 1: Monster, ID 31, cannot escape, probability of 60, and you cannot lose
Item 2: Monster, ID 37, can escape, probability of 30, and you cannot lose
Item 3: Monster, ID 44, cannot escape, probability of 10, and you can lose

Let's say we roll a 23.
It will compare that number to the sum of probabilities step by step:

23 is > 0 but not >= 60 so it falls within the sum of probabilities
23 is not > 30 and <= 90 so it won't pick Item 2
23 is not > 90 and <= 100 so it won't pick Item 3;

It will take Item 1, which a battle start with the monster ID 31 and
you cannot escape or lose the battle.

Example 4: Nested loot tables
    var common = [[3,0,250,60],[3,0,500,30],[3,0,750,10],[3,0,5000,1]];
    var uncommon = [[0,11,1,20],[1,8,1,10],[1,12,1,5]];
    var rare = [[0,14,1,20],[1,21,1,2]];
    var lootTable = [[5,common,0,75],[5,uncommon,0,20],[5,rare,0,5]]
    $gameMap.loot(lootTable)

As you can see in this example, common uncommon and rare are loot tables.
lootTable is also a loot table which contains references to the three others.

The final loot table is composed of these items:
Loot table "lootTable"
Item 1: Item type 5, Loot table "common", quantity 0 and a probability of 75
Item 2: Item type 5, Loot table "uncommon", quantity 0 and a probability of 20
Item 3: Item type 5, Loot table "rare", quantity 0 and a probability of 5

Loot table "common"
Item 1: Item type 3 (Gold), ItemID 0, quantity 250 and a probability of 60
Item 2: Item type 3 (Gold), ItemID 0, quantity 500 and a probability of 30
Item 3: Item type 3 (Gold), ItemID 0, quantity 750 and a probability of 10
Item 4: Item type 3 (Gold), ItemID 0, quantity 5000 and a probability of 1

Loot table "uncommon"
Item 1: Item type 0 (Weapon), ItemID 11, quantity 1 and a probability of 20
Item 2: Item type 1 (Armor), ItemID 8, quantity 1 and a probability of 10
Item 3: Item type 1 (Armor), ItemID 12, quantity 1 and a probability of 5

Loot table "rare"
Item 1: Item type 1 (Armor), ItemID 1, quantity 0 and a probability of 20
Item 2: Item type 1 (Armor), ItemID 5, quantity 1 and a probability of 2

Let's say we roll a 88.
It will compare that number to the sum of probabilities step by step of Loot Table ("lootTable"):

88 is > 0 and >= 75 so it won't pick item 1 (loot table common)
88 is > 75 and <= 95 so it falls within the sum of probabilities
88 is not > 100 and <= 100 so it won't pick item 3 (loot table rare)

Loot table "uncommon", item 2, is picked, so it will roll a new number.
The sum of probabilities for item 2, loot table uncommon is 35, so
the number picked will be between 1 and 35

let's say we rol a 9 for it.
9 is > 0 but not >= 20 so it falls within the sum of probabilities
9 is not > 20 and <= 30 so it won't pick item 2
9 is not > 30 and <= 35 so it won't pick item 3;

so it take item 2 from "loot table uncommon", which is an Armor type with ID 8.


// <== ITEM BAG(S) ==> \\

How to make an item act as a bag of loot:
1) Set item scope to none.
2) Use the notetag <lootTable:[lootTable]>  or <lootTable:[[lootTable1],[....],[lootTableN]]>
example 1: <lootTable:[3,0,500,30]>
example 2: <lootTable:[[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]]>
 
3) If you want to display a message: use a common event with the
variables defined as parameters to help you display the item name, type id and quantity.
Be aware that using a common event will boot you out of the menu.
If not using a common event a random item will be given without returning you to the map.

4) If you want a bag of loot to give another item, you can add loot
tables like this: <lootTable2:[lootTable]>, <lootTable3:[[lootTable1],[....],[lootTableN]]>,...
The program will roll one time on each loot table provided that way.


// <== RANDOM LOOT ON THE MAP ==> \\

1) In event command: script: $gameMap.loot(lootTable)

example: $gameMap.loot([[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]])

2) In event command: script: $gameMap.loot(lootTable,bool*,id*)
If you use bool, the plugin will return the loot table without the
picked element and store it in the variable of id provided. If you
use true, you have to provide a variable id. If you don't you can
ignore them both. (see example 1)

example: $gameMap.loot([[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]], true, 5)

if item 1 is picked ([0,1,1,30]) it will return and store in variable 5:
[[1,1,1,30],[2,1,1,30],[3,0,500,30]] will be left off to "re-roll"
now you can use $gameMap.loot($gameVariables.value(5),true,5) to continue
using the modified table.


// <== SHOP SELLING RANDOM LOOT ==>
A shop selling a random loot bag and have it trigger instantly:
Add the following notetag to a loot table item:

example notetag:
<LTPurchase>
<lootTable:[[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]]>

Once the player buys the item, the loot bag will be opened instantly.
*/
@Astfgl66 not sure if you checked yet, but just needed to know if
everything is correctly written 🙂

also to avoid confusions by other people bumping on this thread.
so they wont make the mistakes I made ^^
Sorry for not responding earlier, I've made a few modifications, mainly clarifying the terms items and loot tables.
You'll find my revised version below.

Code:
// Restructure Helpfile AstfglLT \\ <= by ShadowDragon
/*
// <== BASE STRUCTURE USAGE ==> \\
Loot table structure:
[item1, item2,...,itemN]
Each item is defined this way [itemType, itemId, quantity, probability]

itemType:
0 -> Weapon
1 -> Armor
2 -> Item
3 -> Gold
4 -> Monster [4, encounterId, canEscape, probability, canLose]
5 -> Loot table [5,loot table, 0, probability]

itemId: the id of the item in the database;

quantity: how many of the item you wish to give

probability: the probability that particular item will be picked
in relation to the other items. Not a percentage, unless your sum
of probabilities for all items is = 100.

Loot tables can roll for other loot tables like in this structure:
    var common = lootTable1;
    var rare = lootTable2;
    var legendary = lootTable3;
    var lootTable = [[5,common,0,75],[5,rare,0,20],[5,legendary,0,5]]
    $gameMap.loot(lootTable)


Some examples of how they work.

Example 1:
$gameMap.loot([[0,3,1,30],[1,5,1,30],[2,12,3,30],[3,0,500,30]])

In this example, the loot table is composed of the following items:
Item 1: Item type 0 (Weapon), ItemID 3, quantity 1 and a probability of 30
Item 2: Item type 1 (Armor), ItemID 5, quantity 1 and a probability of 30
Item 3: Item type 2 (Item), ItemID 12, quantity 3 and a probability of 30
Item 4: Item type 3 (Gold), ItemID 0, quantity 500 and a probability of 30

Each probability is equal so the base chance for each item will be 25%.
Let's run through it:

First the plugin will sum all the probabilities (30+30+30+30=120 in this case).
Then it will generate a random number between 1 and the sum. (1 to 120 in this case)

Let's say we roll a 45.
It will then compare that number to the sum of probabilities step by step:

45 is > 0 but >= 30  so the first item is not picked.
45 is > 30 and <= 60 so it falls within the sum of probabilities
of the first two items: item 2 will be picked.
45 is not > 60 and <= 90 so it won't pick item 3;
45 is not > 90 and <= 120 so it won't pick item 4;

so it take item 2, which is an Armor type with ID 5.

If we rolled 100:
100 is > 90 and <= 120 so item 4 will be picked: which is Gold type and gain 500 gold.

Example 2:
$gameMap.loot([[0,1,0,30],[1,5,1,50],[2,12,3,20],[3,0,500,5]])

in this example, loot table is as followed:
Item 1 has: Item type 1 (Weapon), ItemID 1, quantity 0 and a probability of 30 (empty loot)
Item 2 has: Item type 1 (Armor), ItemID 5, quantity 1 and a probability of 50
Item 3 has: Item type 2 (Item), ItemID 12, quantity 3 and a probability of 20
Item 4 has: Item type 3 (Gold), ItemID 0, quantity 500 and a probability of 5

First the plugin will sum all the probabilities (105 in this case)
Then it will generate a random number between 1 and the sum. (1 to 105 in this case)

Let's say we roll a 51.
It will compare that number to the sum of probabilities:

51 is > 0 but >= 30  so the first item will not be picked.
51 is > 30 and <= 80 so it falls within the sum of probabilities
of the first two items: item 2 will be picked.
51 is not > 80 and <= 100 so it won't pick loot item 3;
51 is not > 100 and <= 105 so it won't pick loot item 4;

In the end, ittem 2 is picked, which is an Armor type with ID 5.

If we rolled 99:
99 is > 80 and <= 100 so item 3 will be picked: which is an Item type with ID 12.

Example 3: Monster bags
$gameMap.loot([[4,31,false,60,false],[4,37,true,30,false],[4,44,false,10,true]])

in this example, loot table is as followed:
Item 1: Monster, ID 31, cannot escape, probability of 60, and you cannot lose
Item 2: Monster, ID 37, can escape, probability of 30, and you cannot lose
Item 3: Monster, ID 44, cannot escape, probability of 10, and you can lose

Let's say we roll a 23.
It will compare that number to the sum of probabilities step by step:

23 is > 0 but not >= 60 so it falls within the sum of probabilities
23 is not > 30 and <= 90 so it won't pick Item 2
23 is not > 90 and <= 100 so it won't pick Item 3;

It will take Item 1, which a battle start with the monster ID 31 and
you cannot escape or lose the battle.

Example 4: Nested loot tables 
    var common = [[3,0,250,60],[3,0,500,30],[3,0,750,10],[3,0,5000,1]];
    var uncommon = [[0,11,1,20],[1,8,1,10],[1,12,1,5]];
    var rare = [[0,14,1,20],[1,21,1,2]];
    var lootTable = [[5,common,0,75],[5,uncommon,0,20],[5,rare,0,5]]
    $gameMap.loot(lootTable)

As you can see in this example, common uncommon and rare are loot tables.
lootTable is also a loot table which contains references to the three others.

The final loot table is composed of these items:
Loot table "lootTable"
Item 1: Item type 5, Loot table "common", quantity 0 and a probability of 75
Item 2: Item type 5, Loot table "uncommon", quantity 0 and a probability of 20
Item 3: Item type 5, Loot table "rare", quantity 0 and a probability of 5

Loot table "common"
Item 1: Item type 3 (Gold), ItemID 0, quantity 250 and a probability of 60
Item 2: Item type 3 (Gold), ItemID 0, quantity 500 and a probability of 30
Item 3: Item type 3 (Gold), ItemID 0, quantity 750 and a probability of 10
Item 4: Item type 3 (Gold), ItemID 0, quantity 500 and a probability of 1

Loot table "uncommon"
Item 1: Item type 0 (Weapon), ItemID 11, quantity 1 and a probability of 20
Item 2: Item type 1 (Armor), ItemID 8, quantity 1 and a probability of 10
Item 3: Item type 1 (Armor), ItemID 12, quantity 1 and a probability of 5

Loot table "rare"
Item 1: Item type 1 (Armor), ItemID 1, quantity 0 and a probability of 20
Item 2: Item type 1 (Armor), ItemID 5, quantity 1 and a probability of 2

Let's say we roll a 88.
It will compare that number to the sum of probabilities step by step of LootTable (base):

88 is > 0 and >= 75 so it won't pick item 1 (loot table common)
88 is > 75 and <= 95 so it falls within the sum of probabilities
88 is not > 100 and <= 100 so it won't pick item 3 (loot table rare)

Loot table "uncommon", item 2, is picked, so it will roll a new number. 
The sum of probabilities for item 2, loot table uncommon is 35, so
the number picked will be between 1 and 35

let's say we rol a 9 for it.
9 is > 0 but not >= 20 so it falls within the sum of probabilities
9 is not > 20 and <= 30 so it won't pick item 2
9 is not > 30 and <= 35 so it won't pick item 3;

so it take item 2 from "loot table uncommon", which is an Armor type with ID 8.


// <== ITEM BAG(S) ==> \\

How to make an item act as a bag of loot:
1) Set item scope to none.
2) Use the notetag <lootTable:[lootTable]>  or <lootTable:[[lootTable1],[....],[lootTableN]]>
example 1: <lootTable:[3,0,500,30]>
example 2: <lootTable:[[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]]>
 
3) If you want to display a message: use a common event with the
variables defined as parameters to help you display the item name, type id and quantity.
Be aware that using a common event will boot you out of the menu.
If not using a common event a random item will be given without returning you to the map.

4) If you want a bag of loot to give another item, you can add loot
tables like this: <lootTable2:[lootTable]>, <lootTable3:[[lootTable1],[....],[lootTableN]]>,...
The program will roll one time on each loot table provided that way.


// <== RANDOM LOOT ON THE MAP ==> \\

1) In event command: script: $gameMap.loot(lootTable)

example: $gameMap.loot([[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]])

2) In event command: script: $gameMap.loot(lootTable,bool*,id*)
If you use bool, the plugin will return the loot table without the
picked element and store it in the variable of id provided. If you
use true, you have to provide a variable id. If you don't you can
ignore them both. (see example 1)

example: $gameMap.loot([[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]], true, 5)

if item 1 is picked ([0,1,1,30]) it will return and store in variable 5:
[[1,1,1,30],[2,1,1,30],[3,0,500,30]] will be left off to "re-roll"
now you can use $gameMap.loot($gameVariables.value(5),true,5) to continue
using the modified table.


// <== SHOP SELLING RANDOM LOOT ==>
A shop selling a random loot bag and have it trigger instantly:
Add the following notetag to a loot table item:

example notetag:
<LTPurchase>
<lootTable:[[0,1,1,30],[1,1,1,30],[2,1,1,30],[3,0,500,30]]>

Once the player buys the item, the loot bag will be opened instantly.
*/
@Astfgl66 it looks good with the revision, with a small error:
Code:
Loot table "common"
Item 1: Item type 3 (Gold), ItemID 0, quantity 250 and a probability of 60
Item 2: Item type 3 (Gold), ItemID 0, quantity 500 and a probability of 30
Item 3: Item type 3 (Gold), ItemID 0, quantity 750 and a probability of 10
Item 4: Item type 3 (Gold), ItemID 0, quantity 500 and a probability of 1

the last line (500) should be 5000 in the example.
it looks very clear further more 🙂

Edit:
I updated the previously + fix some 2 typo's to correct it.
it will be fully corrected with your revised version, as (base) wasn't there.

lootTables which you replaced with "item" which is fine.
so there should be no more errors in it with your revised version as well 🙂
Just something I thought of looking at how you currently have to set this up on the developer end: have you considered adding a struct parameter for preconstructed loot tables for an easier UI and then giving the option to provide the loot command a table ID that parses and uses the parameter instead of needing an array?
That would be neat, and so would actually making a window that would display the gained loot without needing an event. Especially if you want to actually use this for loot bags in shops or menu as that would allow for shopping without going back to the map screen every time.

I'm very unlikely to do this though, as I've mostly stopped programming. I just try to provide support and maintenance to my existing plugins.

Original thread: https://forums.rpgmakerweb.com/threads/random-loot.71822/