I’m wanting to alter ores rarities based on depth, but am unsure how to easily go about it. At the moment, all I do is put all the ores in a table, and then just get a random number, and see if it is indexed in the table. Problem is deeper ores are near impossible to find, as it still takes into account ores like Coal, which can’t even spawn in at depths below 60.
["Coal Ore"] = {
Rarity = 150,
MinDepth = 10,
MaxDepth = 60,
},
["Copper Ore"] = {
Rarity = 140,
MinDepth = 10,
MaxDepth = 60,
},
local BlockPercentages = {}
--// Create a block
local function CreateBlock(position)
-- Get random block
local RandomWeight = math.random(1, 1000)
local NewBlock
local Ore = BlockPercentages[RandomWeight]
if Ore then -- Ore
local OreData = MineData.OrePercents[Ore]
if OreData then -- OreData exists
local MinDepth = -(OreData.MinDepth * 3)
local MaxDepth = -(OreData.MaxDepth * 3)
if position.Y <= MinDepth and position.Y >= MaxDepth then -- Within depth
local Block = Blocks:FindFirstChild(Ore)
if Block then -- Block model exists
NewBlock = Block:Clone()
end
end
end
end
end
for ore, oreData in pairs(MineData.OrePercents) do
-- Add ore to table bsaed on rarity
for i = 1, oreData.Rarity do
table.insert(BlockPercentages, ore)
end
end
I’ve looked through here Increasing weight of an ore in a table given a depth value and its min/max depth but didn’t really offer much help