You know that in Murder games, there are usually chances of being the murderer. This number changes for every person in the game.
For example, a server has 3 people, the first one gets 50% chance and the other 2 will get 25% chance. And in bigger server, the numbers would be much more complicated than that.
But you can't just do that normally with math.random
, it's a very complex system, but it would turns out very well in games. So how do you make it?
We could use a table of players and chances for this:
local MurdererChances = { [Player1] = 60, [Player2] = 35, [Player3] = 5 } local RandomChance = math.random(1, 100) local Murderer = nil for Player, Chance in pairs(MurdererChances) do RandomChance = RandomChance - Chance if RandomChance <= 0 then Murderer = Player break end end
As has been pointed out this is a basic solution to the problem, and does not include the changing of chances as a game progresses.