-
What do you want to achieve?
I’d like to make it so that players with a certain gamepass get better chances at egg hatching (3x better). -
What is the issue?
I’m not sure which one of the solutions I currently have is better. -
What solutions have you tried so far?
The Chance variable is a random value from 1 to the Weight of the Egg.
I have 3 solutions that I’ve tried:
1st Solution: If they own the gamepass, they get their chance selected randomly from (1,Weight/3), the lower values being the rarer pets.
This is the function that I use for this solution. Here Pets has been made into an Array from the Dictionary, so that I can sort it from rare to common rarities. The Array has the weights for each pet, for example the rarest pet has the weight 1 and the most common one has the weight 40.
for i,v in pairs(Pets) do
TotalWeight = TotalWeight + v[1]
end
local function ChoosePet(Player)
local Chance
if isLucky == false then
Chance = math.random(1,TotalWeight)
else
Chance = math.random(1,TotalWeight/3)
end
local Counter = 0
for i,v in pairs(Pets) do
Counter = Counter+v[1]
if Chance <= Counter then
return v.Name
end
end
end
2nd Solution: Use the normal chance but use the choosing function 3 times and then give the best pet of the 3.
3rd Solution: The rare pets get their weight multiplied with 3 so they are hatched more often.
Basically in this one I’ll just do this:
for i,v in pairs(Pets) do
TotalWeight = TotalWeight + v[1]
if v[1] <= 20 then
TotalWeight += 2*v[1]
end
end
I haven’t written any code for the other 2, but it’s fairly simple to.
In case none of the solutions I’ve thought of are good, please suggest me one.