Lots of games that have lets say pets have a rarity.
And then lets say someone tries to buy one, it has a higher chance to pick a common one then a rare for instance.
Ik that there are a bunch of posts like this but I looked at them and I cant understand them at all.
I made a post like this before but for the life of me cant find it,
--[[
Rarities in order of occurence:
Common, Uncommon, Rare, Epic, Legendary
]]
local DropChances = { --these dont have to equal to 1, since we are rolling multiple times (once for each rarity)
Common = .75;
Uncommon = .35;
Rare = .12;
Epic = .05;
Legendary = .005;
}
local Rand = Random.new(os.clock()*1000) --only using this bc its really easy to get a number 1 > x >= 0
function Roll()
local CurrentBestRarity = "Common" --your base rarity incase all the rolls fail
for RarityTier, Chance in DropChances do
local NewRoll = Rand:NextNumber()
if NewRoll < Chance then -- remember that it goes from [0-1), so we want #s that are less than the "chance" in the chance table
if DropChances[CurrentBestRarity] > Chance then --if we just rolled a better rarity (lower chance), then use that one.
CurrentBestRarity = RarityTier
end
end
end
return CurrentBestRarity
end
What I usually do (which probably isn’t the most efficient way) is something like this:
local Chance = math.random(1, 10)
if Chance == 1 or Chance == 2 or Chance == 3 then
print("123")
elseif Chance == 4 or Chance == 5 or Chance == 6 or Chance == 7 or Chance == 8 or Chance == 9 then
print("common")
elseif Chance == 10 then
print("rare")
end
This method is probably not the best way to do it, but it’s simple and I use it to make things with 3-4 possible outcomes.