Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[FOUND SOLUTION] Are these pet chances broken? (pet system)

Asked by
Gogulsky 129
4 years ago
Edited 3 years ago

I feel like there's something wrong with the local Chance. People have been reporting that the pets that are under 1% are very hard to hatch. If I make it (0,TotalWeight) I'm pretty sure it won't work. Anyone can tell me if it's broken?

01function ChoosePet(Egg)
02    local Data = Eggs[Egg]
03    local Pets = Data["Pets"]
04    local TotalWeight = 0
05    for i,v in pairs(Pets) do
06        TotalWeight = TotalWeight + v.Rarity
07    end
08    local Chance = math.random(1,TotalWeight)
09    local Counter = 0
10    for i,v in pairs(Pets) do
11        Counter = Counter+v.Rarity
12        if Counter >= Chance then
13            return v.Name
14        end
15    end
16end
0
Try increasing the weight cherrythetree 130 — 4y
0
I already did. I changed it to 1 and it didn't do anything, changed it to 10 and the results were the same, changed it to 100 and the eggs gained a very long cooldown between the next hatch. Gogulsky 129 — 4y
0
The real problem is the local Chance. The math.random(1,TotalWeight) - i think what it does is starts from 1% and it's supposed to start from 0 but I can't put 0 in math.random since that won't work. Gogulsky 129 — 4y

Answer this question