I looked through several threads and answers on this topic but can’t seem to find something that works for my situation. I’m trying to create a loot drop system where each item has a different percent chance to drop when an enemy dies. So lets say I have 5 items with the following drop chances:
item1 - 80%
item2 - 60%
item3 - 50%
item4 - 30%
item5 - 10%
From what info I found on this topic, I could do the following:
var randomNumber : int = Random.Range(1, 101);
if (randomNumber <= 10)
{
//drop item5
}
else if (randomNumber <= 30)
{
//drop item4
}
else if (randomNumber <= 50)
{
//drop item3
}
else if (randomNumber <= 60)
{
//drop item2
}
else if (randomNumber <= 80)
{
//drop item1
}
But this doesn’t seem right to me. According to the code above, doesn’t item1 have a 20% drop rate instead of 80% since it can only drop when the random number is 61-80? Item5 seems to be the only one that is truly a 10% drop rate. The others are more like a range instead of from 1 to the drop rate.
For my system, I only want one item to drop when an enemy dies, but not 100% of the time. So sometimes it can drop something, and somethings it won’t.
Also, what about for items that have the same drop chance? Like if item1 and item2 had a 80% drop chance, do I just do another Random.Range() if the first random number was <= 80? That also doesn’t make sense to me because then it would mean item1 and item2 have an initial 80% drop chance, but then if they are chosen, they have to go through another check where each of the two items has a 50% chance to drop.