I'm wondering how I might store the number of enemies killed during the game as a variable.
Any help would be appreciated.
Any help would be appreciated.
# 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
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
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/