MZ Enemy Counter

Hello Everyone! At begginig, sorry for my bad english.
I'm just starting my adventure with RPG Maker. I've learned a lot over the last few days, but I still have a lot to learn. Currently I am in the process of creating a project which I call "Avalon". It's supposed to be a simple RPG game with mechanics that I like the most in this type of games. Without going into details, I need to introduce the mechanics of counting the enemies I have defeated.

I already tried via "Battle Event"
Condition: Enemy(1) HP <= 0% than Control Veriables +1
Unfortunately, when there is only one enemy, this event does not work. However, if there are more of them (of the same type) the event works, but it always scores 1 less than there are enemies. (example: if there is 3 wolves it count only 2)

I found the plugin "Enemy Kill Counter MZ" by @ToshaAngel, unfortunately it also doesn't work even though I did everything step by step as the author instructed me and after sending him all the screenshots, he said he has no idea why the plugin is not working for me. Here I will note that it does not work even on a new "clean" project without any other plugins.

I also found another solution that I thought might work.
I found the plugin "End Phase Triggers" by HIME. It says "by enabling plugin, the game will perform a check to see if
there are any events that can be run before the battle finishes
."
The plugin was made for RPG Maker MV, but I read that many plugins for MV also work for MZ.
At first I thought it finally worked. However, it turned out that as long as there is 1 enemy everything works fine. But everything gets complicated when there are more enemies. For example, if there are 2 wolves, it counts as 3. If there is 1 wolf and 1 wasp, it counts as 2 wolves and 0 wasps, etc. And the more enemies and more of their types, the weirder it gets.

So please... if anyone have any idea how can i make Enemy Kill Counter or know any free plugin that may work for me just tell me.

Thanks!
You can use VisuStella's Skills and States plugin along with the Battle Core.

Give each of your actors a passive state.

In that state, give it the notetag:
Code:
<JS Post-Damage as User>
if (target.hp<=0)
    $gameVariables.setValue(1, $gameVariables.value(1)+1);
</JS Post-Damage as User>

That notetag is evaluated before the skill finishes, so the code will get executed when a common or troop event would not.
I'll give it a try, but beeing totally honest idk. how to set it up. Can you please explain me this step by step? 'Cuz i don't know if this Code is universal for all enemies and veriables? Do i need to make each passive state for each actor/enemy/veriable?
Moved to: Plugin Requests
@ATT_Turan
That's probably the most straightforward and clean 'plugin route'.

However, depending on what the OP's battle mechanics are, wouldn't this solution be susceptible to
enemy deaths that do not occur directly via actors skill? Most notably, what about dots like poison?

Edit:
So the way I did it in my game is basically I took the death state (e.g. the first state in the database)
and added this notetag:

JavaScript:
<Custom Apply Effect>
if (user.isEnemy()) {$gameVariables.setValue(1, $gameVariables.value(1)+1);}
</Custom Apply Effect>
*Note that this notetag is for MV, and I don't know the VS MZ equivalent.

This way, the counter goes up if the enemy is defeated by any means, or as long as the defeated state was actually applied.
With Hime's plugin, I wonder whether you just mixed up your variables & troop event conditions. The plugin didn't ought to cause weird effects like you describe. 😅

Alternatively, I have a plugin named Cae_AutoSwitchVars. It has options for automatically setting/incrementing switches & variables on various triggers, including battler death. This will trigger regardless of what caused the death. With it, you can just add a tag like this to an enemy's Note box:

<death var: 123, 1>
This will increase variable ID 123 by +1 whenever that enemy dies (tied to the die method). It can be found on my main MZ plugin thread:
(If you try it and it doesn't work, make sure you've downloaded it correctly - there should be a download button displayed on the page, it shows in the top-right for me. I tested this specific feature very recently and it works A-OK for me.)
However, depending on what the OP's battle mechanics are, wouldn't this solution be susceptible to
enemy deaths that do not occur directly via actors skill? Most notably, what about dots like poison?
Good call.

*Note that this notetag is for MV, and I don't know the VS MZ equivalent.
JS On Apply, I believe. It's in the instructions for the OP to easily find 😉
OMG! Caethyril you are AWESOME! Thank you so much! <3
At first i had some weird bug. But after disable VisuStella - Skill States Core plugin everythink i working fine!
Here is screen:
error.png

Do you think it is possible to make this two plugins work together in the future?
Huh, it looks like the error is some kind of loop related to the maximum parameter formula. Does max HP depend on the value of a variable? Unfortunately I don't write compatibility patches for obfuscated plugins like VisuStella's. 😴

You could try changing the load order (save your project to apply Plugin Manager changes before testing), but if that doesn't work I think you'll have to pick one or the other. I'd suggest keeping Skills & States Core, particularly if you're using other VisuStella plugins.

In fact, you can probably replicate my plugin's <death var: X> with Skills & States Core. Try putting this tag in the Note box of state ID 1:

<JS On Add State> if (user.isEnemy()) { const vId = parseInt(user.enemy().meta["death var"], 10); if (vId) { $gameVariables.setValue(vId, $gameVariables.value(vId) + 1); } } </JS On Add State>
...then when an enemy tagged with <death var: X> dies, that should give +1 to variable X. Hopefully. 😮‍💨
Thank you so much! I really appreciate that <3 I'll try what you suggest about changing load order and adding JS into note but if that won't work I'm sure that i want to use your Plugin 'cuz one of my main quest req. to kill x amount of some monsters 🙂

Once again, THANK YOU A LOT <3

Original thread: https://forums.rpgmakerweb.com/threads/enemy-counter.156226/