In this part of the code, it tests to see if x is inside of the segment. If it is, it returns the name of the ore, which is the third value of the segment.
If it never returns anything in that loop, the function returns the default “Stone”. The function does not need any arguments because it accesses chancesTable
directly.
Hmmm just curious now, where should i put my server luck boost to this script.
here or no?
local x = math.random(0,depth) / depth * Boost
Adding a luck booster requires some extra work, believe or not. These segments are not sorted by size, they’re actually randomly placed. With no luck booster, this is fine. But multiplying the x without sorting the segments by size will actually make some unpredictable results that the player won’t like. To make this work, you need to sort segments from least to greatest, and then multiply x by a number lower than 1 to guarantee better chances for smaller segments. I’ll modify the script to do this, give me a few minutes.
Okay thank you a lot, i appreciate that (30 letterssss)
I think this works. If you increase the luck booster value, Diamond shows up a lot more.
local chanceTable = {
Plutonium = 0.5,
Diamond = 0.1,
Coal = 0.35,
Stone = 0.35,
}
-- Convert chanceTable to an array to be sorted
local ores = {}
for i, v in pairs(chanceTable) do
table.insert(ores,{i,v})
end
table.sort(ores, function(a, b)
return a[2] < b[2]
end)
-- Sort chanceTable into segments
local segments = {}
local total = 0
local luckboost = 1 -- increase value to increase luck
for _, data in pairs(ores) do
table.insert(segments, {total, total + data[2], data[1]})
total = total + data[2]
end
local depth = 1000 -- more depth allows for more preciseness for chance, but takes longer to compute
-- 1000 depth allows for chances like: 0.0001.
local function GetOreObtained()
local x = math.random(0,depth) / depth
x = x / luckboost -- forces x to be closer to smaller segments
for _, seg in pairs(segments) do
if seg[1] <= x and x <= seg[2] then
return seg[3]
end
end
return "Unknown"
end
for i = 1, 10 do
print(GetOreObtained())
end
Uhh, maybe i’m just very very very lucky, but bruh it chance is 0.001565(Stellarite), let me check few more times
Okay nvm i just upgraded luck and now it spawns the best ore always(to 34 Mx, so it is normal) Thank you for the help, you are really nice person
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.