Chance (easy random items + luck modifiers)!

local generator = Chance.new({
    Rare = 30,
    Epic = 20,
    Legendary = 10,
    Mythical = 1,
    Exotic = 0.1,
})

local runs = 0
for i = 1, 100 do
    runs += 1

    local type = generator:Run() or "Common"
    if type == "Exotic" or runs == 50 then
        type = "Exotic"
        runs = 0
    end
    
    print(type)
end

With this code, you will get an exotic after 50 attempts. This is unbalanced, but you get the idea.

2 Likes

If you’re making an RNG game like Sol’s RNG, do you find this module hard to use? It’s not necessarily meant for the 1 in x chance system, but it could still work. If it doesn’t work well with RNG games, what interface would you like to see that makes it easiest to work with?

Additionally, it would help if I made a new luck logic system. I currently do not like the luck system, but I’m not sure of how to code a better one. :pensive:

Was waiting for someone to release something like this for a while as developing my own would be poor in areas.

Such a well needed release :+1:

working on a PVE game similar to decaying winter and I need random spawn rates for items, this module will be epic just for that.

Im def going to use this for Role choosing n stuff. Thanks!

wait quick question how would you make it so that if a player wins a game their chances to get a role increases like for murder. So like 10 player playing start off with 10% and then player 4 wins and his chance to become the murder increases.

You can utilize Super.fromResult for this! It’s use case is to turn the results from rolling many times into its assumed chances, but you can also use it for weighted chance values. For example, if they all have a weight of 1, they are all equally likely. You can increase a player’s weight by 1 if they don’t get a special role and reduce it to 1 when they do!

I feel this would be better if it had a weighted option too like LootR and other modules however a cool release non the less.

LootR seems like it has less features, and I didn’t see a weighted option. Could you show me what you mean?

1 Like

It quite literally says weighted in the post title my friend.

Short explanation:

A weighted loot system is <mark>a system that uses weights to determine the likelihood of an item being dropped in a game</mark>. Items with higher weights are more likely to be chosen.

Here is a snippet from the module:

elseif self.Type == "Weight" then
		
		local TotalWeight = 0
		for _, Weight in pairs(ItemNums) do
			TotalWeight += Weight
		end

		local Choice = RandItem:NextNumber(0, TotalWeight)
		for Item, Weight in pairs(ItemNums) do
			
			Choice -= Weight
			if Choice <= 0 then
				Found = self.Items[Item]
				break
			end
			
		end

It might but all I care for in this case is a weight based system instead. I also edited the original reply with a short explanation.

I will probably end up taking a copy, editing it and then integrating such a system into it.

1 Weight = 10%
6 = 60%

etc however it is easier as it does not have a limit of 100% IF I am correct.

Thanks tho.

1 Like

Sorry, I’ve made a mistake! This module isn’t the same as what I’m using now… it doesn’t use an RNG system like in Sol’s RNG like I just said. It still uses percent chances… :cry: My bad for the confusion.

1 Like

All good. However if possible I recommend adding your own weighted system some point in the future and then I wouldn’t mind swapping over.


Why not just use a simple chance system if this module doesn’t fit your needs?

I already am, you should scroll up.

This module needs a rewrite as it’s not up to my standards anymore. Same with Boost.

1 Like

Ah okay. Do you know when you might give it a rewrite/fix up?

I’m closer to finishing Boost right now, I’d have to be inspired to work on Chance again! I’m also hard at work with a game, so it could take a few months to get around to this. For now, you’re free to editing the module as needed for your projects!

1 Like

That’s fine I will probably just stay with what I got for now if you’re going to rewrite it in the near future or distant future.