// 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.
*/