Scripting a Forced Action

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
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
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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.
 
Last edited by a moderator:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
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...)

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
 
Last edited by a moderator:

Xypher

Veteran
Veteran
Joined
Apr 1, 2012
Messages
148
Reaction score
26
Primarily Uses
just add

BattleManager.force_action(self)below the force_action
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
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.
 

Xypher

Veteran
Veteran
Joined
Apr 1, 2012
Messages
148
Reaction score
26
Primarily Uses
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.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
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!
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA
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!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,050
Members
137,571
Latest member
grr
Top