Oh and also, i need to get Gen1 still even if Gen2 have 100% chance,
in case if i increase Value( * 1000) i get just Gen2(100%) and Gen3(80%), but don’t get Gen1(100%)
In this case you need to decide how to pick from the set of gens with 100% chance. I think that the code needs modifying a bit actually as if you had different gens with say 25% it wouldn’t work as expected.
I take it this means you didn’t understand.
Say gen1 has 100% and gen2 has 100% and there are no other gens. Which one should be picked?
Player should get both in same time (Gen 1 Amount + 1 and Gen 2 Amount + 1) and have a chance to get an Gen 3 and Gen 4 and etc.
I just joined an random server without normal multi, so you couldn’t see normally, on vip server with good multi i will earn all my gens which are 100% in same time
So if you get gen 10, really that means all the gens from 1 up to and including 10? It should be pretty simple for you to just select all the ones lower than the one returned by GetRandomGen
Yeah each gen from 1 to 10 will get +1 to their amount(ofc if they 100% chance, or if player is lucky enough to get it with smaller chance)
local min,max = math.min(Sum,1),math.max(Sum,1)
local RandomNumber = math.random(min,max)
??? How this gonna help with getting all instead of best one, i already have solution about randomizing gen with chance tho thanks @McThor2
oh I didnt saw the solution it didnt hightlighted from me well ok.
So do you want it to be an individual roll for each gen then? It is not clear exactly how you want this to work.
Yeah an individual roll, like you have an chance to get all gens in a one second(although it almost impossible, but there is an still chance), not you will get best one
Okay then that is actually fairly simple to do as well. Here is an example of a function that will return a random set of gens given your ChancesModule.
local function GetRandomGenSet()
local genSet = {}
for genName, odds in pairs(ChancesModule) do
if math.random() < 1/odds then table.insert(genSet, genName) end
end
return genSet
end
Not sure if it has been mentioned yet but that error occurs when math.random
's second argument is greater than its first.
Ugh i bit don’t understand how this works, it just prints me table with Gen 1 infinitely
What did you do to print out gen1 infinitely?
Changed
local function GetRandomGen()
-- Sort the chances in least likely to most likely order
local chancesArray = {}
for genName, chance in pairs(ChancesModule) do
-- Im assuming here that the current values in Chances Module are given like 1 in X odds
table.insert(chancesArray, {Name = genName, Value = 1/chance})
end
table.sort(chancesArray, function(a, b) return a.Value < b.Value end)
-- Pick a random gen
local randomNumber = math.random()
for _, info in ipairs(chancesArray) do
if randomNumber < info.Value then return info.Name end
end
end
to
local function GetRandomGenSet()
local genSet = {}
for genName, odds in pairs(ChancesModule) do
if math.random() < 1/odds then table.insert(genSet, genName) end
end
return genSet
end
Okay, so how are you testing it? The odds for getting gen 2 + are quite low.
it just run around 100 times in a second so i can check if it works, but i can’t see table fast, so i need to click it first, can i somehow print all table values?