#Random/rng system
1 messages · Page 1 of 1 (latest)
weighted tables
What about luck boosts
weight * luckMultiplier
So if i have
Common = 1000
Legendary = 1
And if i have luck 1000?
Common will be
1,000,000 and legendary
1000?
local rarityTable = {
{Rarity = "Epic", Chance = 1/25},
{Rarity = "Rare", Chance = 1/5},
{Rarity = "Uncommon", Chance = 1/2},
{Rarity = "Common", Chance = 1}
}
local luck = 175 -- Calculated as a procentage
local function roll()
local rng = math.random()
print("RNG Before Luck:", rng)
rng = rng / (1 + luck / 100)
print("RNG After Luck:", rng)
for _, rarity in rarityTable do
if rarity.Chance >= rng then
print("Obtained:", rarity.Rarity)
print("Chance: 1 in " .. 1 / rarity.Chance)
break
end
end
end
roll()``` Here's something I wrote up
just don't go negative and you should be good