Not sure how i would make a rng type system that increases with luck.
but also if you have enough luck it would decrease the chances of the more common things
for example
with 1 luck it would look something like this
You can use equations to weight your items. Exponential functions might be a good idea.
If I were you I’d just play around on a graphing calculator, here’s one I made for ["CommonItem"]
function getRandomItem(Table)
local total = 0
for i, v in pairs(Table) do
total += v
end
local r = RNG:NextNumber(0, total)
local add = 0
for item, v in pairs(Table) do
if r > add and r <= add + v then
return item
end
add += v
end
return 0
end
This function gets a dictionary with the result as the key, and the chance as the number. For example:
local Items = {
Common = 100;
Uncommon = 30;
Rare = 10;
Epic = 2;
Legendary = 0.1;
}
The nice thing about this function is that it doesn’t require all the numbers to add up to 1 or 100. With the example table, it would return strings such as "Uncommon" or "Epic".
There are quite a few math equations you can use for this, here’s some I came up with. Gaussian curve, sine curve, quadratic curve. Here’s a demo for 1 to 100 and back to 1 for example
ok these look cool (mainly cuz ion understand them) but in a roblox sense what would x be?, because im guessing i cant just plug it into a script and have it work
nvm pretend like i crossed this out cuz idk the way to do it
x is the luck idk why i didnt think about it for a second
but this does work for me ty
Ill mark this as a solution as its a way ive found that im pretty sure works
local Luck = 1
function GetRaritys()
local Raritys = {
{"Common", 100 * Luck},
{"Uncommon", 50 * Luck},
{"Rare", 25 * Luck},
{"Epic", 12.5 * Luck}
}
for i, v in ipairs(Raritys) do
if Raritys[i][2] > 100 then
if Raritys[i+1] and Raritys[i+1][2] >= 100 then
Raritys[i][2] = -((Raritys[i][2]/100)*1.15) + 100
elseif Raritys[i][2] > 100 then
if Raritys[i+1] then
if not (Raritys[i+1][2] >= 100) then
Raritys[i][2] = 100
end
else
Raritys[i][2] = 100
end
end
end
end
return Raritys
end
Luck = 2
print(GetRaritys(), Luck)
Luck = 3
print(GetRaritys(), Luck)
of course the luck numbers and the raritys could use some tweaking to your liking but this works fine for me atleast
Sorry for the late response, I’m not sure what you’ve done with your solution but you can just scale the graphs. If you want luck to max out at different values then you change x to 1/ratio. So for example if we’re going from 100 max luck to 50 max luck I’d change x to 1/(50/100) = 2. So now I use 2x instead of x. (See purple graph). If you want the max rarity to decrease you just change the whole equation by the factor you are decreasing by (see blue graph)