Scripting a Forced Action

Hi guys - did some searching as well as a lot of trial and error, and couldn't find the answer to this.  Can anyone help me out?

I'm trying to have a character immediately use a skill to damage all enemies when a State is removed from them.  I've called the force_action method with the Skill ID (176) and tried a few different targets (such as 2 and -1), and added in a Play ME script line to confirm that the block is being hit.

When the state is removed, the ME plays but the Action doesn't seem to happen at all.  No animation, no battle log entries, no damage.  It's as if the line wasn't there.  What is happening and how can I get it to force the action properly?  Thanks!!

Code:
  #--------------------------------------------------------------------------  # * Remove State  #--------------------------------------------------------------------------  alias :remove_state_with_specials :remove_state  def remove_state(state_id)    remove_state_with_specials(state_id)    if (state_id == 94 and self.id == 12 and self.hp > 0)      force_action(176, -1)      Audio.me_play('Audio/ME/Fanfare1')    end  end
It works for me.

When I say

Code:
class Game_Battler    #--------------------------------------------------------------------------  # * Remove State  #--------------------------------------------------------------------------  alias :remove_state_with_specials :remove_state  def remove_state(state_id)    remove_state_with_specials(state_id)    force_action(26, -1) # heal spell    Audio.me_play('Audio/ME/Fanfare1')  endend
And I use the "guard" command which adds a guard state and then removes it next turn, I heal myself.
Game_Battler#force_action only replaces the set of planned actions for this battler, it does not automatically execute the set action. Action execution is handled by the battle scene.

During event execution in battle, Scene_Battle#process_forced_action is called repeatedly to check if a forced battler was registered in the BattleManager and starts action execution if necessary (see Scene_Battle, line 519).

This might be an approach:

(extending refresh_status is quite experimental though. The method is used to update the battle status on the screen, so "abusing" it might not be the perfect idea when it comes to compatibility...)

Spoiler
class Scene_Battle   # Force Actions every time the status has to be updated:  alias_method🙂refresh_status_ILC_executeForceActions, :refresh_status)  def refresh_status    refresh_status_ILC_executeForceActions    process_forced_action  endendclass Game_Battler   # Force Action: Heal (26) when the Guard state (9) is removed.  alias_method🙂erase_state_ILC_forceAction, :erase_state)  def erase_state(state_id)    erase_state_ILC_forceAction(state_id)    force_event_action(26, self.index || 0)  if state_id == 9  end   # Store Event Actions  def force_event_action(*args)    BattleManager.force_action(self)    force_action(*args)    Audio.me_play('Audio/ME/Fanfare1')  endend
However, unless revamped the battler class does only support one set of actions at a time. Forcing a new action before the previously planned actions were executed (e.g. the battler made its turn) will actually skip them.

When multiple actions are triggered at once only one of them will get executed at the moment since force_action replaces the battlers action set completely.

No Common Events are triggered by these skill executions.

When the battler dies, flees or is healed by the "Recover All" command, all states are removed by calling clear_states, which does not trigger the actions at the moment
just add

BattleManager.force_action(self)below the force_action
However, unless revamped the battler class does only support one set of actions at a time. Forcing a new action before the previously planned actions were executed (e.g. the battler made its turn) will actually skip them.

When multiple actions are triggered at once only one of them will get executed at the moment since force_action replaces the battlers action set completely.
Are you sure? Reason I'm skeptical is when I use a force action on an enemy, they get the forced action and their action for that turn. Has happened 100% of the time so far.
Are you sure? Reason I'm skeptical is when I use a force action on an enemy, they get the forced action and their action for that turn. Has happened 100% of the time so far.
force action clears the battler's actions.

yanfly's core lets to keep the current actions as well so you might be using that.
force action clears the battler's actions.

yanfly's core lets to keep the current actions as well so you might be using that.
That explains it then, as I have Yanfly's. I had to add a state on all forced actions to avoid the extra action even, as that was driving me crazy for a while!
Just wanted to say thanks to everyone that offered help here.  For the moment I was able to get around the problem safely by forcing a Common Event (containing a forced action) to run when the State wears off, but this is a very obtuse way to do it.  I'll try your more elegant solutions out next week to see what works!

Original thread: https://forums.rpgmakerweb.com/threads/scripting-a-forced-action.35486/