Tie a variable to defeated enemy?

Say I want to have a side quest to defeat 30 slimes. Is there a way to make a variable increase by 1 each time a slime is defeated? Here's my idea.

When you talk to the NPC that starts the quest, it sets the variable "Slimes Defeated" to 0. Then he tells you to go defeat 30 Slimes. After you kill a slime, the variable goes up by 1. Then, when you talk to the NPC again, there can be a conditional branch that checks the variable "Slimes Defeated" and if it's less than 30, he'll tell you how many you've defeated or how many you still need to defeat (by just doing some variable math and displaying a variable as text)

I can do all of this if there's a way I can create a variable that increases by 1 for each of the enemy that's defeated. The only way I can currently think of doing this is by troop, but then you won't get rewarded if you defeat one and flee from the others in the troop.

Thanks in advance to anyone who can help!
by troop, but then you won't get rewarded if you defeat one and flee from the others in the troop.
then you're doing it the wrong way.
you should use troop events, one event per each slime in the troop, to increase the variable whenever that slime is defeated.

however if you do this you need to either use an immortal state to protect the slime until the event is triggered (and then remove the state to confirm the kill) or you need to use a plugin that gives you after battle triggers for troop events, because by default those events will not trigger for the last enemy killed.
Sorry, could you go into some more details about how the immortal state works? I need to make the enemy immortal, and then removal that immortal state once HP reaches 0 after I trigger the event to increase the variable?

What do I need to specify in the state to make them immortal?
"immortal" state means a state with the trait to resist the death state (#1) that is automatically applied when any battler reaches HP=0.
This immortal state needs to be added at turn 1 of your battle before anything else.

and then for each slaim you make a troop event to be triggered at HP=0 that contains two commands: one control variable to count up the number of kills and one remove state from that specific slime to allow it to die.
Okay, I think I got it! I'm going to test it out now. First, when the HP of the enemy reaches less than or equal to 0%, I increase the variable, and then I remove the state. Since it's HP is less than or equal to 0, it will instantly be defeated once the state is removed.

Leaving the text boxes blank in the state editor means that the player will never know that the enemy has this mystery state.

I want to have the span for these events all just be battle.

One question, does the order of the event pages in the troop matter?
no, and keep in mind that the span means how often the events are triggered. it will work with battle in this case because it is the death that triggers it and you only trigger death once.
Okay, one last question.

Also, while this isn't actually related to the question asked in the topic, I'm using Galv's quest plugin for this, and I want to know if there's a way to have a common event run to complete the quest objective for the player once they hit a certain number of defeats of the slime. Would I run that as Autorun or Parallel? I know I would want it to be a conditional branch that checks the variable, but I'm not sure if autorun or parallel is what I'm supposed to use. I suppose I could also run that check in the troop if this wouldn't work, but I don't see a way to check that the battle finishes in the troop editor.

EDIT: During my testing, I've noticed it doesn't say "Slime is defeated", and instead they just fade away kinda awkwardly after they hit 0HP, almost like it's resolving too late. Any idea how to fix that?
show us what you did and we might be able to tell you - screenshots of the two states as well as the troop events
Actually, you can do it exactly the way you described in your first post, if you use this:
https://forums.rpgmakerweb.com/index.php?threads/kill-counter.56923/

You could also do it without a plugin by adding the number of slimes in the troop to the variable at the start of the battle. If you win the battle, it means you defeated them all. If you lose, the game will end and you'll have to reload a saved game, with the variable set to whatever it was when you saved. The only way this approach won't work is if you allow escape from battle or you have evented battles with "continue when lose" checked.
Thanks for your plugin Shaz! I'll try to implement it tonight!

But for the sake of my own education, here's some screenshots...

Spoiler: Knockout State
upload_2019-6-3_19-4-57.png

Spoiler: Immortal State
upload_2019-6-3_19-5-29.png

Spoiler: Troop Event Page 1
upload_2019-6-3_19-6-7.png

Spoiler: Troop Event page 2
upload_2019-6-3_19-6-41.png

Original thread: https://forums.rpgmakerweb.com/threads/tie-a-variable-to-defeated-enemy.109642/