One way to do “luck” is to re-roll and pick the better of the two rolls, Risk of Rain 2 does this for their luck. But this algorithm should be to a low “luck” number, even 3 rolls is pretty high.
local rarityRoll = math.random()
-- for each luck re-roll
for i = 0, luck do
-- replace rarityRoll with the new roll, if higher.
rarityRoll = math.max(math.random(), rarityRoll)
end
Hi, I had a go at amending the code, rather than setting a threshold, it may be easier to simply compare the rarityRoll to the rarity.chance then reduce the rarityRoll by that amount. If the for loop does not meet any conditions i.e. does not reach the break point, you must have met the condition for the highest rarity level. The dropper bonus can then be added into the loop to increase the likelihood that your rarityRoll is higher (or the chance threshold is lower as below).
while true do
local rarityRoll = math.random() -- Roll for balloon rarity
for i, rarity in ipairs(balloonRarities) do
if rarityRoll <= rarity.chance - dropperBonus then --dropperBonus added here
print(rarity.name)
break
else
rarityRoll = rarityRoll - rarity.chance
end
print(balloonRarities[5].name) --Amend integer to highest level or default.
wait(0.001)
end