Luck

## Radovan's Notes

`local function AddDrop(Table, strName, intChance, intMin, intMax, intMinLevel)
 Table.Drops = Table.Drops or {}
 Table.Drops[strName] = {Chance = intChance, Min = intMin, Max = intMax, MinLevel = intMinLevel}
 return Table
end`

`AddDrop(NPC, "money", 100, 200, 300)
AddDrop(NPC, "item_smallammo_small", 20)
AddDrop(NPC, "armor_craft_belt_attachment_bootsenergy", 0.05)`

`local intChance = (tblInfo.Chance or 0) * (1 + (entKiller:GetStat("stat_luck") / 45))
local ItemChance = 100 / math.Clamp(intChance, 0, 100)
if math.random(1, (ItemChance or 100)) == 1 then
 local intAmount = math.random(tblInfo.Min or 1, tblInfo.Max or tblInfo.Min or 1)
 local entLoot = CreateWorldItem(strItem, intAmount, npcTarget:GetPos() + Vector(0, 0, 30))`

While killing Combine Grunts, chance of dropping money is 100%, and a number between $200 and 300.
Also, 20% of dropping Small Rounds and 0.05% of dropping the boots, just 1.

local intChance = Chance from the NPC drop table \* (1 + (the users stat level / 45))
my stat level was 25. 15 without the hobo armour, and the 7 Luck gives 14 Luck, so you start with 1 Luck.
1 Luck gives intChance = base chance \* 1.0222... to start with already
25 Luck gives intChance = base chance \* 1.555...
So 1 Luck means there is a 0.05111...% chance of boots, and a 102.222...% chance of money.
25 Luck means there is a 0.0777...% chance of boots, and a 155.555...% chance of money.

math.Clamp(intChance, 0, 100) limits intChance between 0 and 100, so this reduces the 102%, 155% chances on Money to 100%, and any possible negatives to 0%.
For the money, ItemChance = 100/100 = 1, and for the boots, ItemChance = 100/0.0777... (for 25 Luck) = 1285.71428571
These numbers represent the number of NPCs that need to be killed in order to get 1 of these items (1 in 1285 chance for boots).

math.random(1, (ItemChance or 100)) generates a number between 1 and ItemChance (1285 for boots). This is like throwing a 1285 sided dice. The if statement then requires that if the number rolled is equal to 1, then you win. If not, no drop.

math.random(tblInfo.Min or 1, tblInfo.Max or tblInfo.Min or 1) generates a random number between the set minimum (200 for money) and set maximum (300 for money), so between 200 and 300 (or just returns 1 for the boots). This is the intAmount.
It then creates the item if successful, and sets the quantity of that item, should it be stackable like money.

So if it is stated that the money drops 100% of the time, and you do not find it 100% of the time, then this means that if math.random(1, (ItemChance or 100)) == 1 returns a false.
This means that ItemChance does not equal 1.
This then means that math.Clamp(intChance, 0, 100) does not equal 100, because intChance is not equal to or above 100.
intChance is therefore actually a number between 0 and 100.
It was found from my killing of 367 Combine Grunts that there were 69 cases where no money dropped. This means that money dropped in 298 out of 367 kills, giving a percentage of ~82% (overestimating for missed drops).
This implies that the value of intChance = 82, and since I was wearing full Hobo Set with 7 Luck (totalling 25 Luck), then:
82 = baseChance \* (1 + 25/45) = baseChance \* 1.555...
Therefore baseChance = 82/1.555... = 53%

Therefore it is apparent that the money drop chance on Combine Grunts had been changed from 100 to, most likely, 50% since the older version.

Radovan (talk) 15:47, 2 April 2016 (CDT)

It was later confirmed by The Commander that it is in fact exactly 50% in the code. Radovan (talk) 04:50, 3 April 2016 (CDT)