VXAce Common event fired in one battle does not execute until the beginning of the next

I do volunteer support for SierraLee's VX Ace game "The Last Sovereign", we've gotten a bug report that hasn't been reproduced but that I find credible, and it's obvious enough from looking at the game database what must be happening.

We have a skill that is basically the execution of three existing skills, simulating a magic spell that allows the PC to cast three spells in sequence. The ordinary configuration of the skill replicates the first of these skills, and there is an additional effect where a common event is called. The common event than uses the Battle/Force Action command twice to have the PC use the remaining two skills. (They target all enemies.)

What is happening is that the use of the first spell kills the last enemy in a battle encounter, so the skills forced by the common event do not happen in that battle. At the beginning of the next battle encounter, the common event DOES fire, casting the remaining two spells.

This skill is an end of game feature for an actor who is generally not a favorite among players, and the situation is unlikely to occur often because of the relatively small number of battle encounters remaining in the game content.

I don't have the bandwidth to rigorously test for variables like "Does it happen if the second skill is the one that kills the last enemy?" or "Does it happen if the actor is not in the active party of the next encounter?" (not unlikely). I'm describing the scenario here in the hopes that someone has seen it before and/or knows an easy fix.

If nobody has any suggestions, I'm probably just going to recommend it just be ignored.
If possible you could do a Conditional Branch If Enemy then Force Action, then repeat after each sequential spell. So therefore if spell one kills last enemy then the remaining two spells will not be queued up.
If possible you could do a Conditional Branch If Enemy then Force Action, then repeat after each sequential spell. So therefore if spell one kills last enemy then the remaining two spells will not be queued up.

Looks promising...

The Enemy radio option on 3rd page of the Conditional Branch menu lets you choose which "target enemy" you want with numbers 1. - 8. Looks like there's space for enemy names but they're blank when the interface is called from within the common event editor. I'm assuming I want to select 1. But this mean that the condition will only fire if the first enemy in the troop is still present or if any remaining enemies are present?

The other question is "Is the action that gets suspended in the background the two force actions of the skills, or is the execution suspended before the common event is called, leaving the conditionals unchecked until the next combat begins?"

Thanks for the suggestion!
I'd suggest having all three spells in the common event with a conditional branch before the second and third that contains something like,
$game_troop.alive_members.size > 0
$game_troop.alive_members.any?
If true cast spell, else false exit event processing
So hopefully once a spell kills the last enemy the common event is exited and not paused until the next combat begins.
Only a suggestion so hope it works

The above code is a guess, so if someone with more knowledge on battle events could confirm or correct it that'd be appreciated.

Edit: Could this work?
class Scene_Battle < Scene_Base
alias clear_action_forced_on_terminate terminate
def terminate
BattleManager.instance_variable_set(:@action_forced, false)
clear_action_forced_on_terminate
end
end
I'd suggest having all three spells in the common event with a conditional branch before the second and third that contains something like,
$game_troop.alive_members.size > 0
$game_troop.alive_members.any?
If true cast spell, else false exit event processing
So hopefully once a spell kills the last enemy the common event is exited and not paused until the next combat begins.
Only a suggestion so hope it works

Yeah, it was a good idea, but as I suspected, the execution of the common event doesn't start until the next combat begins, so the troops are alive.

I have tested with the MAT stat on the (group effect targeting) skill user turned up to 10,000 on three sequential battles. 1st spell killed everyone in the 1st battle, 2nd spell killed everyone in the 2nd battle, 3rd spell didn't fire in the 3rd battle, and that happens with or without the suggested conditional.

So it's definitely the execution of the common event that's getting held to the next battle, not the forced action that is getting suspended. I therefore don't want to mess with the suggested ruby script modification.

One thing worth noting is that the 2nd spell executes at the start of the second battle before the player is prompted to enter their commands for the actors during the 1st turn. Maybe something could be jiggered together in terms of a script conditional to check if the battle turn is 0. That seems to be within the possibilities of the battle event conditionals in the troops definition interface...
1st spell killed everyone in the 1st battle, 2nd spell killed everyone in the 2nd battle, 3rd spell didn't fire in the 3rd battle
Curious why the 3rd spell didn't fire.
I'd suggest having all three spells in the common event
So just double checking, you did remove the damage formula(1st) from the spell and only process spells/damage from within the common event? Since the 3rd spell doesn't fire I'd of assumed the 2nd would follow suit if you'd done this.

Well since noone else is suggesting anything, you should probably send some screenshots of your Skill and Common Event for more context.
Curious why the 3rd spell didn't fire.

So just double checking, you did remove the damage formula(1st) from the spell and only process spells/damage from within the common event? Since the 3rd spell doesn't fire I'd of assumed the 2nd would follow suit if you'd done this.
No. Because I'm dumb and apparently hadn't registered you recommending that part. Will give a common event with three forced actions a whirl.
So moving everything to the common event with null action on the root skill is a no go. (It's actually clear that the author SierraLee had previously tried that.)

What happens in that case is the first thing that happens in the battle interface is that every enemy has a little "Failed" graphic pop up on them before the common event is called and the first real attack happens. This is more of a distraction than the existing bug. It does prevent the second attack from happening in the next fight though.

I've posted screenshots of the existing configuration. You can see on the lefthand menu that the skill is called 494: Arcane Storm. Skills 492 and 493, Arcane Lightning and Arcane Ice are defined above and you can see that they are called in the common event 27 defined in the second screenshot. The damage data for 494: Arcane Storm replicates the now deprecated 491: Arcane Fire, so it's easy to just change 494's damage to None and add 491: Arcane Fire to the front of the common event. As indicated above, the result is that you get the 494 skill doing "Failed" damage to everyone, while the common event is then called and 491 kills everyone. Then 493 is NOT called as a forced action at the start of the next battle.

So for clarity, the order of operations in the current setup is:

1.) Skill 494 gets called, does damage to all enemies, kills everyone.
2.) Common event 27 is called.
3.) First battle ends.
4.) Common event 27 does not begin processing, but gets held in the background.
5.) Event code processes with dialogue until the next battle event.
6.) Next battle event begins.
7.) Common event 27 begins processing.
8.) First forced action fires, skill 493 is called, kills everyone.
9.) Second forced action fires before battle ends, null result.
10.) Second battle ends.

Adding conditionals to common event 27 for $game_troop.alive_members.size > 0 or $game_troop.alive_members.any? doesn't help because they won't be evaluated until the second battle has already started and there's a new group of enemies.

So my idea is to try and have a conditional that checks a script to determine if the battle state is in "turn 0", before any player actions have been taken, and null it out in that case. Assuming that's possible.
Figured it out.

Setting a conditional on BattleManager.in_turn? == false in the common event that exits processing does the job.

Original thread: https://forums.rpgmakerweb.com/threads/common-event-fired-in-one-battle-does-not-execute-until-the-beginning-of-the-next.182817/