MV I'm trying to add " Battle end" to Yanfly's Utility Common Events

Hi everyone, I added this code to the plugin to run a common event at the start of each battle:

JavaScript:
Yanfly.UCE.Game_System_onBattleStart = Game_System.prototype.onBattleStart;
Game_System.prototype.onBattleStart = function() {
  Yanfly.UCE.Game_System_onBattleStart.call(this);
  if (Yanfly.Param.UtilCommonEvents['battleStart'] > 0) {
    $gameTemp.reserveCommonEvent(Yanfly.Param.UtilCommonEvents['battleStart']);
  }
};

I am trying to add another piece of code to replicate the effect at the END of each battle, but without success.
I changed "Game_System.prototype.onBattleStart;" to "Game_System.prototype.onBattleEnd;" but this method doesn't exist! My Javascript knowledge is pretty poor, it's just amazing that I managed to add the trigger for the start of the battles ...
That's why I ask someone more experienced for help.

Link to Yanfly's plugin: Utility Common Events
Is there a reason you can't use the Battle Won/Escape Battle triggers? Does this need to take place in the battle scene?

Aside from that, there's BattleManager.processVictory(), but I'm not certain that just calling an event from that has an interpreter to make the game wait.

You could also try a combination of Yanfly's Base Troop Events to make an event that goes off if all enemies are at 0% HP, use the plugin to put it into every troop, then use HimeWorks' End Phase Triggers to allow the event to be run properly.
You could also try a combination of Yanfly's Base Troop Events to make an event that goes off if all enemies are at 0% HP, use the plugin to put it into every troop, then use HimeWorks' End Phase Triggers to allow the event to be run properly.
Thanks, I have thought of a similar alternative, in case I am unable to solve with the plugin.

Is there a reason you can't use the Battle Won/Escape Battle triggers? Does this need to take place in the battle scene?
From what I understand, "battle won" and "escape battle" don't work if I lose the battle.
I am trying to use "Battle end" to run my common event for each type of battle outcome.
your main problem is that you misinterpreted the script command you're using. Please read its name more carefully:
reserveCommonEvent

nothing there says "start" the common event, it says "reserve time for preocessing that event when the engine has finished all other current processes".

there simply is no command to directly start a common event from script at all, that is why you have to use other methods than scripts for that.

don't work if I lose the battle.
if you check the box on the battle processing window for "can lose" then you get a third branch for that.
however that only works for evented battles, for random battles you'll need to find the equivalent yourself (I don't know the code)
From what I understand, "battle won" and "escape battle" don't work if I lose the battle.
I am trying to use "Battle end" to run my common event for each type of battle outcome.
How are you starting these battles? Typically, if you lose a battle the game is over, so there are no common events to worry about.

If you're calling them from an event with Battle Processing, there's a Lose branch right there you can put event commands into (including calling a common event).
In my game there aren't random encounters, all enemies are events visible on the map. There are also a lot of boss battles during the cutscenes,
My intention is to take advantage of the Yanfly plugin to avoid having to repeat the call of common events for all possible battles.
Unless I enter a conditional branch for defeat, the game moves me directly to the game over screen, which is why I would like to simplify everything by calling a common event at the end of each battle, regardless of the outcome.
The code I added for the start of the battle seems to work fine in the tests I ran.
In my game there aren't random encounters, all enemies are events visible on the map.
Unless I enter a conditional branch for defeat...
This is definitely the easiest thing to do. Check the box for the defeat conditional, then paste in your common event call. Only takes a few seconds for each enemy event, as opposed to the time spent writing code and inevitably troubleshooting it 😉

It's how I would do it. If you're determined to try to automate it further, I don't have any better suggestions than the code and plugin options I gave in my first reply. Someone else might know a better way.
This is definitely the easiest thing to do. Check the box for the defeat conditional, then paste in your common event call. Only takes a few seconds for each enemy event, as opposed to the time spent writing code and inevitably troubleshooting it 😉

It's how I would do it. If you're determined to try to automate it further, I don't have any better suggestions than the code and plugin options I gave in my first reply. Someone else might know a better way.
Ok, then I'll follow the suggestion of your first post! Thanks for the answers!

Original thread: https://forums.rpgmakerweb.com/threads/im-trying-to-add-battle-end-to-yanflys-utility-common-events.151674/