gachaponHelper.lua utility file - VanaDev/Vana GitHub Wiki
Category: Utility Lua-Based Scripts
Type: nil
Notes: Used as a return value from a function passed in to indicate to indicate that a global item should be kept.
Type: number
Notes: Used as a return value from a function passed in to indicate to indicate that a global item should be discarded.
Type: number
Notes: Used to determine the default chance of obtaining a level 20 book for a 4th job skill.
Type: number
Notes: Used to determine the default chance of obtaining a level 30 book for a 4th job skill.
Return(s):
- N/A
- args: table
- Optional - args["gachItem"]: number
- args["items"]: table
- items["id"]: number
- items["weight"]: number
- Optional - items["qty"]: table
- Optional - qty["maximum"]: number
- Optional - qty["minimum"]: number
- args["globalItemWeightModifier"]: number or function
- Return(s): item_keep or item_discard (default is item_keep)
- Argument(s): item: table
Chances: Lots of global items and their chances are defined in this utility Lua file. The chance is a relative weight, which can be confusing. Here are some scenarios to illustrate this concept:
- If there are 100 items all of 1 chance, each item has a 1% chance.
- If there are 100 items all of 2 chance, each item has a 1% chance.
- If there are 100 items all of .5 chance, each item has a 1% chance.
- If there are 50 items all of 1 chance, each item has a 2% chance.
- If there are 100 items, 50 of them of .5 chance, 50 of them of 2 chance, the entire group of .5 chance items will be selected approximately 25% of the time while the remaining 50 would be selected approximately 75% of the time. So this means that each item from the .5 chance group has a .5% chance of being selected and each item from the 2 chance group has a 1.5% chance of being selected.
- If there are 10 items and each one has a weight incremented by 1 (so 1, 2, 3, ..., 10), the item in the 10th position will be selected 10 times more than the item in the first position. The item in the second position will be selected twice as much as the item in the first, but only 1/5 the frequency of the 10th item.
Phrased differently, an item WILL be picked - there's a 100% chance of getting an item. The items essentially fight over what the chance of being selected is, so it's based on the number of items and what all the different weights are.
The number used as the baseline in the global items is 1. This is supposed to represent an average chance to be selected, but the probabilities of all of the others probably distort the number.
This also means that you can apply a multiplier to all the items and either emphasize them or obscure them as desired. This is what globalItemWeightModifier is in the case where a number is provided. All of the global item weights have the multiplier applied.
Usage:
gachapon({ ["items"] = items, -- Decrease the chance of getting things from the global item list ["globalItemWeightModifier"] = .5, });
gachapon({ ["items"] = skills, ["globalItemWeightModifier"] = function(item) -- Only pass non-scrolls through if math.floor(item["id"] / 10000) == 204 then return item_discard; end return item_keep; end, });