I'm making a game like MM2 - short for 'murderer mystery 2', which is a murder game.
You can buy cases, but i want a certain class of item to be rarer of the other;
How do i make a percentage of something.
Like if i want 70% of the acre to be filled with dandelions and the other 30% filled with other flowers and plants?
local rarities = { Common = { probability = 699/1000 }; Uncommon = { probability = 200/1000 }; -- i.e. 2/10 Rare = { probability = 100/1000 }; -- i.e. 1/10 Legendary = { probability = 1/1000 }; }; function getRarity() local probability = Random.new(tick()):NextNumber() local cumulativeProbability = 0 for name, item in pairs(rarities) do cumulativeProbability = cumulativeProbability + item.probability if probability <= cumulativeProbability then return name, item end end end
So here, you want the probabilities to add up to 1.
IE: 699/1000 + 200/1000 + 100/1000 + 1/1000 = 1
So if you were to change the probabilities, you need to make sure that the probabilities add up to 1.
You may notice how the code is written as 100/1000 instead of 1/10 for example. This is because it's a lot easier to see the distribution of things when all items have a common denominator.
you can do something like this:
local chance = Random.new(tick()):NextInteger(1,100) -- This is PURE random local rarity = if chance =>1 and =<29 then rarity = "Rare" -- 30% chance elseif chance =>30 and =<100 then rarity = "Common" -- 70% chance end end
You get the idea
I have the answer For the 2nd question, And if you go a little creative with it, you might answer the 1st question By Yourself
local chances = math.random(0,1) ------ your function if chances <= 0.7 then ------ dandelions elseif chances >0.7 then ---- other flowers and plants