How to increment a value after a successful battle

In random encounters I would like to increment a specific variable - AFTER the battle is successful. Because I know what troops I would use I assume I would do this in the troops event page, how ever because I have never given troops events before, I am unsure how to say - when you complete, if you are successful, do this, else, do nothing.
I think there's an issue with the troop events, in that one set to run at the end of a battle doesn't actually run. There is a script fix to make sure it does.


With random encounters, you cannot say "if successful, do this, else do nothing". You can only do that with evented enemies using the Call Battle Processing command, which gives you a "continue when loser" option, which then gives you a "do this if win, do this if lose" branch.


If you JUST want to see how many battles you've fought (not won, but if losing battles always means game over, the number of battles fought will always be the number of battles won, as long as you only use random battles), you can look at $game_system.battle_count
That wouldnt work, because of the way I have set up the events. You might be on a map where an event start (randomly) and encounters are enabled, at the same time you might be doing a quest. so the quest enemies would interfere with the random encounters, thus invalidating the results. Is there a way to say, using the troop event, variabl +1 so long as you fought said troop? I have tried, in the troops event, to just increment a value, but using debugging scripts to see what that variable is after battle - shows it never increments...my understanding is that troop events are auto run or parallel process?
So you have random encounters AND map-based encounters? Do you want to count ALL of them, or just the random ones, or just the map ones?


You could still use that variable, but with your map based encounters, before calling the battle processing command, increment another variable. So you will have $game_system.battle_count, which is ALL the battles you've fought, and the variable, which is all the map-based battles you've fought. If you need to know how many random encounters, just subtract the variable from the $game_system one.


It's all a roundabout way of overcoming the troop issue though. If you can find the script that forces "end of battle" troop pages to run, you can do exactly what you're after. I THINK Tsukihime wrote it.
http://himeworks.wordpress.com/2013/05/12/post-battle-events/
@Tsukihime 

Can you please explain your script. I have tried it as such:

and it doesn't do as it should
That works for me.
attachicon.gif
Capture.PNG
and it doesn't do as it should
That works for me.

In that case, it looks like either you did something wrong when installing the script, or there is an incompatibility with another script you've installed.

Can you give us a list of the scripts you're using?

Original thread: https://forums.rpgmakerweb.com/threads/how-to-increment-a-value-after-a-successful-battle.16600/