Help With Randomized Event Process

Hi all, thanks for taking the time to read this, I'll try to make it as short as possible.

I'm working on a murder-mystery-esque game where someone new dies every night. I want the victim to be chosen by random from the possible characters, but with a percentage shift based on other factors (the idea is to allow the player the oppotunity to change the likely hood of someone dying).

Right now I've set up a preliminary code where I gather everyone's percentage chance to die.
First, I check if each character is already dead - in which case their chance is set to 0
Then I check if the player did something that would ensure their safety - in which case their chance is set to 0
If neither of these are true, then every character will start with a base of 10 for their likelyhood of dying.
But I want to influence that, as seen by their relationship level with the murderer (hidden from the player of course). If they have a bad relationship, it would add 10 to their chance. I will be adding other factors/variables/switches that would influence this as well.

Screenshot 2024-05-07 114853.png


What I'm having trouble with now is figuring out how to take those percentages and run an event that will choose the next victim. (I'll have a switch for who's chosen).

There are 9 possible victims each night, depending on how many are alive/safe. (there won't be any situations where everyone is at 0% chance)

Any ideas?
Thanks in advance!
I've updated it a bit to something that kind of works.
I've aded a random variable branch to each character's branch.
If the variable is less than their survival chance, they'll die.
If they do, then the processes stops.
If it doesn't, then it'll move onto the next character.
Screenshot 2024-05-07 150050.png

This works in terms of finding someone to die (I put I loop command at the end to go through things again if it doesn't hit anyone)

But this does naturally raise the percentage of the first person in the list over the others. So if anyone figures out a way to run them all at once or something let me know, please.
This would be considerably easier to do with JavaScript, but it should be possible with eventing.

The first tweak I'd suggest, though not necessary, is to rename "chance" to "weight", since that would more accurately describe what those variables do 😉

Next, to randomly pick someone with chances directly proportional to weights:
1. Pick a random number (let's call it X) between 1 and the sum of weights.
2. For each character:
- If X is smaller or greater that their weight, they die, and we stop
- Otherwise, decrease X by their weight
I describe how to do something very similar here. In your case, you would manipulate the weight as you described in your first post rather than increasing the chances of a date.

This would be considerably easier to do with JavaScript, but it should be possible with eventing.

The first tweak I'd suggest, though not necessary, is to rename "chance" to "weight", since that would more accurately describe what those variables do 😉

Next, to randomly pick someone with chances directly proportional to weights:
1. Pick a random number (let's call it X) between 1 and the sum of weights.
2. For each character:
- If X is smaller or greater that their weight, they die, and we stop
- Otherwise, decrease X by their weight
Is there an event command that can calculate the sum of the 9 weight variables?
Is there an event command that can calculate the sum of the 9 weight variables?
There isn't. That's part of what I meant by it being a bit of a pain with pure eventing.

Though you could set a variable to a script:
[1,2,8,9,13,42].map(x=>$gameVariables.value(x)).reduce((a,b)=>a+b)
Replace 1,2,8,9,13,42 with the IDs of the variables you want to sum.
Is there an event command that can calculate the sum of the 9 weight variables?
You can just use Control Variables repeatedly to add them all in. It's less efficient than using a script call, but...it's only 9 commands 😛

Original thread: https://forums.rpgmakerweb.com/threads/help-with-randomized-event-process.168446/