Enemy KO Variable

I'm wondering how I might store the number of enemies killed during the game as a variable.
Any help would be appreciated.
I recommend doing it with a script since you have to bypass the fact that, whenever the last enemy dies, the battle ends and no troop event is triggered on battle end.
I don't know if that specific script suggested above even exists, but there are three ways around the battle end problem that are know to work.

All solutions require that in every troop you have one event for every enemy that gets triggered on HP=0 and counts up the variable (and whatever else you want).
This will get you most of the count, but the last enemy killed in every battle will not trigger its troop event by default. Solutions around this problem are:

1) a temporary immortal state
you need a state that grants immunity to the death state (#1). Then you need a troop event that automatically applies this state to all enemies on turn #0.
And you change the troop events above to remove the immortal state after the kill variable has been counted up.
That will result in the enemies only dying after the variable is counted.

2) Tsukihime's battle conditions
I don't have the link but Tsukihime wrote a script with additional conditions for troop events especially to counter the problem of troop events not triggering at battle end.

3) using battle processing with the escape and win options triggered.
If the party has won, you'll know that they have killed the last enemy that hasn't triggered and simply increase the kill count by 1.
If they escaped, the kill count will be correct and needs to remain unchanged.
This solution has some drawbacks in the form that all battles need to be evented (no random battles) and that it only works with a single counter for all enemies (the other solutions could count different variables like "slimes killed" "undead killed" etc)
@Kes I believe I gave you the script for this. Maybe you can share?
@TheoAllen I'm not sure if this is quite what the OP is looking for, as it is the number of enemies killed by each individual actor - though I suppose you could do a variable for each actor and a final one which adds all the individual ones together.

Anyway, for what it's worth, here's the script:
Code:
# Given by TheoAllen in a forum post 28 June 2018
# https://forums.rpgmakerweb.com/index.php?threads/counting-enemy-kills-per-actor.96958/#post-875846
# Gives total enemy defeats per actor.
# To obtain results, store it in a variable by using this script call
# $game_actors[id].kill_count

class Game_Battler
  attr_writer :kill_count
  alias exe_damage execute_damage
  def execute_damage(user)
    puts self.hp
    exe_damage(user)
    puts self.hp
    if self.hp == 0
      user.kill_count += 1
    end
  end

  def kill_count
    return @kill_count ||= 0
  end
end

class Game_Variables
  alias :kill_var :[]
  def [](var_id)
    case var_id
    when 67 # <-- variable id
      $game_actors[1].kill_count
    when 68
      $game_actors[2].kill_count
    when 69
      $game_actors[3].kill_count   
    when 70
      $game_actors[4].kill_count   
    when 71
      $game_actors[5].kill_count   
      
    # Add more ....
    # Don't delete below this line
    else
      kill_var(var_id)
    end
  end
end
It's alright, I just need the code so I can edit it here without the need to open RM 😀
Code:
class Game_Battler
  attr_writer :kill_count
  alias exe_damage execute_damage
  def execute_damage(user)
   exe_damage(user)
   if self.enemy? && self.hp == 0
     $game_variables[<ID HERE>] += 1 # Replace <ID HERE> with variable id
   end
  end
end
Thank you everyone for all your assistance.

This thread can now be closed.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/enemy-ko-variable.110267/