Counting enemy kills per actor

No need to worry about Yanfly Battle Engine, since I used it myself on my project and I personally confirm it has no conflict. If you have another time to debug this, try global search (even though I'm not even sure if we need to even search this)
Code:
def item_apply
Any battle related script you have in mind? Or maybe you killed the enemy in unusual way by using damage formula?
@TheoAllen
The only 2 scripts brought up by searching for def item_apply were Tsukihime's Effects Manager and Yanfly's Elemental pop-ups. Disabling them made no difference.

The enemies were killed using vanilla Attack.
Alright, let's try another method. First put my backtracer : https://github.com/theoallen/RGSS3/raw/master/Untranslated/Script Backtracer.rb
You can put it anywhere as long as it's above main

Then replace my kill count script with this
Code:
class Game_Battler
  attr_writer :kill_count
  alias exe_damage execute_damage
  def execute_damage(user)
   backtrace
   exe_damage(user)
   if self.dead?
     user.kill_count += 1
   end
  end

  def kill_count
   return @kill_count ||= 0
  end
end
It should open a file of trace log whenever an attack is struck.
@TheoAllen This is what it records when a blow is struck
Spoiler: notepad output
Created on : 2018-06-28 13:52:07 +0100
=================================================
extra kill count --- Line: 11:in `execute_damage'
Game_Battler --- Line: 519:in `item_apply'
Yanfly Battle Engine --- Line: 1415:in `item_apply'
Yanfly Elemental Pop-ups --- Line: 147:in `item_apply'
Yanfly Battle Engine --- Line: 3001:in `apply_item_effects'
Scene_Battle --- Line: 597:in `invoke_item'
Yanfly Battle Engine --- Line: 3109:in `invoke_item'
Yami Battle Symphony --- Line: 3350:in `invoke_item'
Yami Battle Symphony --- Line: 847:in `block (2 levels) in action_skill_effect'
Yami Battle Symphony --- Line: 847:in `times'
Yami Battle Symphony --- Line: 847:in `block in action_skill_effect'
Yami Battle Symphony --- Line: 844:in `each'
Yami Battle Symphony --- Line: 844:in `action_skill_effect'
Yami Battle Symphony --- Line: 528:in `block in perform_actions_list'
Yami Battle Symphony --- Line: 516:in `each'
Yami Battle Symphony --- Line: 516:in `perform_actions_list'
Yami Battle Symphony --- Line: 860:in `action_autosymphony'
Yami Battle Symphony --- Line: 531:in `block in perform_actions_list'
Yami Battle Symphony --- Line: 516:in `each'
Yami Battle Symphony --- Line: 516:in `perform_actions_list'
Yami Battle Symphony --- Line: 3316:in `block in use_item'
Yami Battle Symphony --- Line: 3314:in `each'
Yami Battle Symphony --- Line: 3314:in `use_item'
Yanfly Battle Engine --- Line: 2990:in `execute_action'
Yami Battle Symphony --- Line: 3373:in `execute_action'
Yanfly Lunatic States --- Line: 642:in `execute_action'
Vlue Basic Combos --- Line: 58:in `process_action'
Scene_Battle --- Line: 48:in `update'
Yanfly Command autobattle --- Line: 406:in `update'
Scene_Base --- Line: 14:in `main'
Moghunter weather effects --- Line: 817:in `main'
SceneManager --- Line: 23:in `run'
Khas Ultra Lighting --- Line: 2003:in `run'
Main --- Line: 7:in `block in <main>'
F12 Fix --- Line: 47:in `call'
F12 Fix --- Line: 47:in `block in rgss_main'
:1:in `block in rgss_main'
:1:in `loop'
:1:in `rgss_main'
F12 Fix --- Line: 37:in `rgss_main'
Main --- Line: 7:in `<main>'
ruby:in `eval'
That's... an interesting development. I was expecting "Nope, it's not even opening a log file" because I was expecting that somehow my script didn't even get executed. But it did get executed. So apparently my script worked, but didn't get the "dead?" check worked. Was checking on Yami's script too that apparently should have no problem. Other scripts shouldn't interfere execute_damage method

We're going to try a different combination of checking if enemy is dead. Since we've confirmed that my script is actually being executed. So my method to debug
Code:
class Game_Battler
  attr_writer :kill_count
  alias exe_damage execute_damage
  def execute_damage(user)
   puts dead?
   exe_damage(user)
   puts dead?
   if self.dead?
    user.kill_count += 1
   end
  end

  def kill_count
   return @kill_count ||= 0
  end
end
What you do, make a skill or atk that deals 99999 or make a new battler that has 1 HP, whatever you like it. (basically one kill an enemy)
Turn on the console. Once an attack is struck (and enemy is killed), it should print "false" then "true".
If it's "false" and "false" then dead check somehow not working.
If it's "false" and "true" then somehow the kill count is not added.
It gives false, false.
So it's true dead check is not working. Let's switch to HP check instead.
Code:
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
It should prints HP before get damage, and after get damage. And properly adds kill count.
The console showed this, which seems to me to be the correct HP reduction as each actor hit the enemy (there are 2 enemies)
upload_2018-6-28_15-18-27.png


However, variables 67 and 68 did not update.
For a sake of test consistency though, you should test it with one enemy and one actor. One enemy only have wait, not attacking since I had a hard time reading the console log.

However, if the variable didn't get updated, then it's another story. So here if you believe HP check worked. We need to make sure the kill count registered properly before playing with game variables.
> Make a test map.
> Make an event trigger a battle.
> Make another event.
> The another event only contains a script call "puts $game_actors[1].kill_count".
> Don't turn off the console.
> Play only with actor 1 in party.
> Kill all enemies using actor 1 only.
> Get back to map.
> Trigger the event that has the script call.
> If you put 2 enemies in the battle event and u killed em all. The console window will print "2"
Console printed out 2.
Then it worked, and I don't see why the variable didn't get updated. But we can try a different method. We switch to manual update. Do you know how to implement calling a common event every time the battle ends?

The idea is to call the common event to update the variable value every time the battle ends.
To prove this, on the battle event, adds control variable, id 67, with script call "$game_actors[1].kill_count" after the battle ends
Then show message to show a variable. Of course you need to remove variable link script on post #16

Edit: and im goin bed since it's going to be a midnite here. So expect a late reply
Argh!!!!!!!!!!! I could shoot myself!

With all the chopping and changing around, that extra bit went missing. I put it back in, and the variable updated perfectly correctly.

Grovelling apologies. The last few posts have been unnecessary. I am so very sorry.
But I am also deeply grateful for all your time and attention. It has been such a help.
Then it solved. I was about to give another shoot if it didn't work lol.
@TheoAllen Yes, it's solved. I feel really bad about the extra work you had to put in because of my error. I've tested it out thoroughly, and everything is smooth.

Original thread: https://forums.rpgmakerweb.com/threads/counting-enemy-kills-per-actor.96958/