hello, so ive made this implementing the system into mine
function multiplyToWhole(egg)
local multiplier = 1
for _, pet in pairs(eggModule.Eggs[egg].Rarities) do --Essentially edits the multiplier so that even the smallest decimal will become whole
local function zeros(amount)
local total = "1"
for i = 1, amount do
total = total.. "0"
end
return total
end
local split = string.split(tostring(pet["Chance"]), ".")
if split[2] ~= nil then
if tonumber(zeros(string.len(split[2]))) > multiplier then
multiplier = tonumber(zeros(string.len(split[2])))
end
end
end
print(multiplier)
for _, pet in pairs(eggModule.Eggs[egg].Rarities) do
pet["Chance"] = pet["Chance"] * multiplier
end
end
eggModule.ChoosePetTest = function(eggToHatch)
multiplyToWhole(eggToHatch)
local TotalWeight = 0
for _,PetData in pairs(eggModule.Eggs[eggToHatch].Rarities) do
TotalWeight = TotalWeight + PetData["Chance"]
end
local Chance = math.random(1,TotalWeight)
local Counter = 0
for i,PetData2 in pairs(eggModule.Eggs[eggToHatch].Rarities) do
Counter = Counter + PetData2["Chance"]
if Chance <= Counter then
local rarityTab = eggModule.Eggs[eggToHatch].Pets[i]
local chosenPet = rarityTab[1] or rarityTab
local cost = eggModule.Eggs[eggToHatch].Cost
local rarity = PetData2["Rarity"]
local percent = PetData2["Percent"]
local legendtier
if rarity == "Legendary" then
legendtier = PetData2["Tier"]
else
legendtier = 1
end
local divinetier
if rarity == "Divine" then
divinetier = PetData2["Tier"]
else
divinetier = 1
end
return chosenPet, rarity, percent, cost, legendtier, divinetier
end
end
end
just wanted to know if this will work.
also just in case, i have my table setup like this:
["Common Egg"] = {
Cost = 500,
Secrets = {"Giant Kitty","TV"},
Rarities = {
["Doggy"] = {["Chance"] = 37.38595, ["Rarity"] = "Common",["Percent"] = "37.3"},["Kitty"] = {["Chance"] = 27.5, ["Rarity"] = "Uncommon",["Percent"] = "27.5"},
["Bunny"] = {["Chance"] = 25, ["Rarity"] = "Rare",["Percent"] = "25"},["Bear"] = {["Chance"] = 10, ["Rarity"] = "Epic",["Percent"] = "10"},
["Deer"] = {["Chance"] = 0.1, ["Rarity"] = "Legendary",["Percent"] = "0.1",["Tier"] = 1},["Dragon"] = {["Chance"] = 0.01, ["Rarity"] = "Legendary",["Percent"] = "0.01",["Tier"] = 2},
["Totem (A)"] = {["Chance"] = 0.002, ["Rarity"] = "Legendary",["Percent"] = "0.002",["Tier"] = 3},["Totem (B)"] = {["Chance"] = 0.002, ["Rarity"] = "Legendary",["Percent"] = "0.002",["Tier"] = 3},
["Giant Kitty"] = {["Chance"] = 0.00004, ["Rarity"] = "Secret",["Percent"] = "4e-05"},["TV"] = {["Chance"] = 0.00001, ["Rarity"] = "Secret",["Percent"] = "1e-05"}
},
Pets = {
["Doggy"] = {"Doggy"}, ["Kitty"] = {"Kitty"},
["Bunny"] = {"Bunny"},
["Bear"] = {"Bear"}, ["Deer"] = {"Deer"}, ["Dragon"] = {"Dragon"}, ["Totem (A)"] = {"Totem (A)"}, ["Totem (B)"] = {"Totem (B)"}, ["Giant Kitty"] = {"Giant Kitty"}, ["TV"] = {"TV"}
}
},