Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a randomizing system like in Murder games?

Asked by 6 years ago
Edited 6 years ago

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?

0
math DoYouKnowHowToRead -13 — 6y
0
maffs? Konethorix 197 — 6y
0
But only when they are equal. If one chance is greater than the other, you must also handle that; in your system greatest values are in negative form. DoYouKnowHowToRead -13 — 6y
0
Not sure what I was even saying, you don't need to randomly sort at all. This would work, I'm not sure what you're getting at. 5% of the time, a random integer generated between 1 and 100 will be 25-30, the same chance for it to be 30-35, et cetera. Avigant 2374 — 6y
View all comments (2 more)
0
You do not understand, the RandomPercentage is not the issue. It is a simple line of code. When you assemble bits & pieces together you make something entirely new. DoYouKnowHowToRead -13 — 6y
0
You're not making any sense. Once the random percentage is <= 0 the chance is the one we want to select. Avigant 2374 — 6y

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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.

0
Very well DoYouKnowHowToRead -13 — 6y
Ad

Answer this question