Timed Random Kill List

Hello everyone. First off, thank you for taking the time to read this form. My sister and I are working on a horror-themed game. The game's main mechanic is what we are calling the Kill List. Instead of the location being abandoned like in most horror games, we are hoping to get the same level of tension like that in John Carpenter's The Thing where you and 30 NPCs are in a isolated location and the threat is killing the cast off randomly one by one.
The Kill List is currently set on a timer so it is a race against the clock. However we had two issues are our small test scale of only 10 NPCs.

The first issue was that as time went on the killer killed two NPCs instead of one like it was suppose too. We don't know why that is happening however this doesn't occur to often. This was when the coding was in v 1.0.

The second issue; which is game breaking, is that at random times as the killer is slowly taking out the cast of 10 NPCs the entire game locks up. This happens about around 5-8 NPCs killed off. We are completely baffled as to why this is happening.

The engine we are using is RPG Maker VX Ace. Now we have the Kill List 2.0 set in Common Events and this is coding for it below.

Spoiler: Kill List Coding
Kill List v2.0 part 1.png Kill List v2.0 part 2.png Kill List v2.0 part 3.png

Note that the coding in the images are only just for one person. It is also set to trigger at different times during the game-play as well. If anyone knows or has a idea of how to stop the game from completely locking up, please I would like to hear your input.
Hello, since the event is incomplete it is hard to tell what happens. On the top of that you have a label which has unknown uses. That said please keep in mind that everything I say is just a guess.

First of all you don't need do use that many commands. All you need is a single variable storing the number of characters currently alive and one switch for each character (the switch tells you if the character is dead or alive). Once you have that you can use a variable to generate a random number between 1 (inclusive) and the number of characters (inclusive). When you kill a character you decrease that variable by 1 and when it reaches 0 you trigger something different (game over?).

Spoiler: Once you do that you can set up your event like this:
> Get random variable (let's call it a from now on)
> Loop (we'll use this to ensure that each time you roll a number you actually kill a character)
> Check the character switch (to do this it is better if you use a bunch of contiguous switches)
> > If the switch is on (that means the character is already dead)
> > > Increase a by 1 (this checks the next character assuring a kill every time)
> > > If (a > number of characters)
> > > > a = 1
> > If the switch is off (the character is still alive)
> > > Turn the switch on (kill the character)
> > > If (number of alive characters > 0)
> > > Decrease number of alive characters
> > > Break Loop
> If (number of alive characters == 0)
> > Do something (game over?)

As you can see doing it this way is much shorter in therms of how many commands you use. Not only does this mean it is easier to correct mistakes, it also improves performance because you don't have to check things many times.

I made this using only event commands. If you want to do it using a script call you can do it that way too.

Spoiler: If you want to do it using a script call this is the way
Code:
myrn = Random.new
vid = put_your_id_here
# This is the variable id where you store the number of alive characters.
# Be sure to change "put_your_id_here" with its real id.
x = first_flag_switch
# first_flag_switch is the 1st switch id used as a flag for character deaths.
# Be sure to replace it with the first id of your bunch of switches.
# Example: if you are using switches from 11 to 31 then that line would be
#          x = 11
tot = number_of_characters
# Change "number_of_characters" to be your total amount of possible targets
a = myrn.rand(tot)
loop do
  if $game_switches[a + x]
    a += 1
    a = 0 if (a == tot)
  else
    $game_switches[a + x]
    if ($game_variables[vid] > 0)
      $game_variables[vid] -= 1
      break
    end
  end
end
NOTE: This code doesn't cover the part when all characters are dead since I don't know what you want to do with it. You can still do it using a conditional branch as event command. The variable you have to check is still the same.

NOTE 2: Lines starting with # are comments containing instructions. If the code doesn't fit just read them and delete them after understanding them.
> Get random variable (let's call it a from now on)
> Loop (we'll use this to ensure that each time you roll a number you actually kill a character)
> Check the character switch (to do this it is better if you use a bunch of contiguous switches)
> If the switch is on (that means the character is already dead)
> Increase a by 1 (this checks the next character assuring a kill every time)
> If (a > number of alive characters)
> a = 1
> If the switch is off (the character is still alive)
> Turn the switch on (kill the character)
> If (number of alive characters > 0)
> Decrease number of alive characters
> Break Loop
> If (number of alive characters == 0)
> Do something (game over?)

Thank you so much for your time and assistance. I am going to use this instead of what I have currently. Again, thank you so much.
I had to edit my previous post because somehow the indentation I used was not displayed properly (at least when I took a look at it). It is extremely important to see it because it explains which if goes inside a branch and which one does not. As a rule every time the number of ">" increases it means that branch/statement is inside a previous branch.

Please don't forget to nest them correctly or it will not work.

If you want to use a script call in my previous post I included a script call version for it as well. Be sure to read instructions (comments) and eventually delete them if they don't fit in a single line or if the whole code doesn't fit in the box.

I also fixed a mistake where I used the variable containing the number of alive characters instead of the number of possible targets (characters) in both, my pseudo-code and its explanation above.

Original thread: https://forums.rpgmakerweb.com/threads/timed-random-kill-list.104620/