How would I configure this code to work with 2x luck?
function ChoosePet(player, Egg)
local Data = Eggs[Egg]
local Pets = Data["Pets"]
local TotalWeight = 0
for i,v in pairs(Pets) do
TotalWeight = TotalWeight + v.Rarity
end
local Chance = math.random(1,TotalWeight)
local Counter = 0
for i,v in pairs(Pets) do
Counter = Counter+v.Rarity
if Counter >= Chance then
return v.Name
end
end
end
You could consider dividing the chances by 2, and then randomizing it again if they don’t have “2x luck”. For example, 1/50, and then later on if they don’t have 2x luck, you randomly select again, making it 1/100 with 1x luck, and 1/50 without.
i never done this before but probably this will work?
function ChoosePet(player, Egg)
local luck = 2
local Data = Eggs[Egg]
local Pets = Data["Pets"]
local TotalWeight = 0
for i,v in pairs(Pets) do
(TotalWeight = TotalWeight + v.Rarity) / luck
end
local Chance = math.random(1,TotalWeight)
local Counter = 0
for i,v in pairs(Pets) do
Counter = (Counter+v.Rarity) * luck
if Counter >= Chance then
return v.Name
end
end
end