Enemy KO Variable

Status
Not open for further replies.

Ragpuppy87

Veteran
Veteran
Joined
Apr 17, 2019
Messages
308
Reaction score
245
First Language
English
Primarily Uses
RMMV
I'm wondering how I might store the number of enemies killed during the game as a variable.
Any help would be appreciated.
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,421
Reaction score
596
First Language
Italian
Primarily Uses
RMVXA
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.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,431
Reaction score
7,712
First Language
German
Primarily Uses
RMMV
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)
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
@Kes I believe I gave you the script for this. Maybe you can share?
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
@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
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
It's alright, I just need the code so I can edit it here without the need to open RM :D
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
 

Ragpuppy87

Veteran
Veteran
Joined
Apr 17, 2019
Messages
308
Reaction score
245
First Language
English
Primarily Uses
RMMV
Thank you everyone for all your assistance.

This thread can now be closed.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,867
Reaction score
5,240
First Language
Dutch
Primarily Uses
RMXP

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.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,470
Members
137,821
Latest member
Capterson
Top