Hello, I need help with this, i don’t what it named
This is my List (Using weight chance)
local Items = {
{“Basic”, 1},
{“Basic+”, 0.5},
{“Basic++”, 0.1},
{“Regular-”, 0.01},
{“Regular”, 0.001},
{“Regular+”, 0.0005},
{“Regular++”, 0.0001},
{“Common-”, 0.00005},
{“Common”, 0.00001},
}
So my Question is how do i make that to RNG like 1/0 or 1/1 or 1/100
I was trying to make game like Sword Factory i tried to make board to show all rarities with the multiplier and RNG but i dont know how do i make the RNG? any solution for this?
This is code how to get the item
local multiplier = 1
for _, item in pairs(Items) do
local function zeros(amount)
local total = “1”
for i = 1, amount do
total = total… “0”
end
return total
end
local split = string.split(tostring(item[2]), “.”)
if split[2] ~= nil then
if tonumber(zeros(string.len(split[2]))) > multiplier then
multiplier = tonumber(zeros(string.len(split[2])))
end
end
end
for _, item in pairs(Items) do
item[2] = item[2] * multiplier
end
local TotalWeight = 0
for _,ItemData in pairs(Items) do
TotalWeight = TotalWeight + ItemData[2]
end
function chooseRandomItem()
local Chance = math.random(1,TotalWeight)
local Counter = 0
for _,ItemData in pairs(Items) do
Counter = Counter + ItemData[2]
if Chance <= Counter then
return ItemData[1]
end
end
end