Hey!
I have a weighted chance system. The module looks like this:
local module = {}
module.Chances = {
["Naruto Pack"] = {
["Naruto S1"] = 0.3,
["Sasuke S1"] = 0.3,
["Sakura S1"] = 0.3,
["Kakashi S1"] = 0.3,
["Gaara S1"] = 0.3
},
["One Piece Pack"] = {
["Luffy S1"] = 0.3,
["Zoro S1"] = 0.3,
["Nami S1"] = 0.3,
["Robin S1"] = 0.3,
["Sanji S1"] = 0.3
},
["Dragon Ball Pack"] = {
["Goku"] = 0.3,
["Gohan S1"] = 0.3,
["Krillin S1"] = 0.3,
["Piccolo S1"] = 0.3,
["Vegeta S1"] = 0.3
}
}
return module
The script looks like this:
local function GetCard(pack)
local ChanceTable = {}
if PacksModule.Chances[pack] then
ChanceTable = PacksModule.Chances[pack]
else
return
end
print(ChanceTable)
local Weight = 0
for _, Chance in pairs(ChanceTable) do
Weight += (Chance * 10)
end
local ranNumber = math.random(1, Weight)
Weight = 0
for prize, chance in pairs(ChanceTable) do
Weight += (chance * 10)
if Weight >= ranNumber then
return prize
end
end
end
I was wondering how I could turn the chances from the module into percentage to display to the user