How to have a party member counterattack with a specific skill.

I'm trying to set up a skill that gives an ally a state that enables this.

The state, while set on the character, makes them retaliate immediately against the enemy that last damaged them by calling a common event that causes a "force action" of the specific skill I want them to retaliate with.

The problems I'm encountering:
  1. I can't figure out how to trigger the common event call upon the actor taking damage.
  2. I can't figure out how to have the "force action" skill target the enemy that just damaged that actor.
So, I tried to make my own counterattack skill in my first game (because I didn't want any additional scripts, and didn't like the engine's default setting), and what I did could help you. It has some issues, one being that you'll have to modify all enemy attacks manually.

First, you'll put something like this in the damage formula:

v[105]=b.id ; v[106]=a.index() ; a.atk * 4 - b.def * 2

The first variable is the ID of the target (i.e. the actor being hit), the second is the index of the enemy that did the attack. After the ; is the damage that should be done.

Then you link a common event to each of the enemy attacks (which triggers only when the enemy attack hits, so not when they miss or the actor evades). In that common attack you'll check if the targeted actor has the state (in my case, the state was applied when an actor had a certain accessory), make sure that they are not paralysed, or have any other state that prevents them from acting, and if they are able to act, you force the action:

$game_actors[$game_variables[105]].force_action(165, $game_variables[106]);
BattleManager.force_action($game_actors[$game_variables[105]])

using the variables you got from the damage formula. 165 is the skill that will be used in the counterattack. This worked great for me, HOWEVER, if this happened before the actor did the action that the player chose for them, that action didn't happen (this was a problem with only one actor who had low agility and so often acted after the enemies). I think it could be solved somehow, maybe someone can come up with a way to remember the chosen action and have it execute when it should be. That would help me to correct my counterattack for the 25th anniversary edition of my game :LZSlol:

This is my clumsy solution, but maybe one of the counterattack scripts does it easily and elegantly.
So, I tried to make my own counterattack skill in my first game (because I didn't want any additional scripts, and didn't like the engine's default setting), and what I did could help you. It has some issues, one being that you'll have to modify all enemy attacks manually.

First, you'll put something like this in the damage formula:

v[105]=b.id ; v[106]=a.index() ; a.atk * 4 - b.def * 2

The first variable is the ID of the target (i.e. the actor being hit), the second is the index of the enemy that did the attack. After the ; is the damage that should be done.

Then you link a common event to each of the enemy attacks (which triggers only when the enemy attack hits, so not when they miss or the actor evades). In that common attack you'll check if the targeted actor has the state (in my case, the state was applied when an actor had a certain accessory), make sure that they are not paralysed, or have any other state that prevents them from acting, and if they are able to act, you force the action:

$game_actors[$game_variables[105]].force_action(165, $game_variables[106]);
BattleManager.force_action($game_actors[$game_variables[105]])

using the variables you got from the damage formula. 165 is the skill that will be used in the counterattack. This worked great for me, HOWEVER, if this happened before the actor did the action that the player chose for them, that action didn't happen (this was a problem with only one actor who had low agility and so often acted after the enemies). I think it could be solved somehow, maybe someone can come up with a way to remember the chosen action and have it execute when it should be. That would help me to correct my counterattack for the 25th anniversary edition of my game :LZSlol:

This is my clumsy solution, but maybe one of the counterattack scripts does it easily and elegantly.

I'll try your solution. Thank you.

You also mentioned "counterattack scripts." I searched a bit and couldn't really find any. I know HimeWorks has one, but any link to it I found is dead.
Oh, I thought there were tons of counterattack scripts, but, like you, I can't find that many now. I have among my downloads a script by Fomar that sets a skill that is used when counterattacking, but it doesn't state the terms, so I don't know if it can be used in commercial projects (and I haven't tried it myself, so no idea if/how it works). The link to Fomar's script leads to Archeia's script repository, definitely a useful place. Too bad about Hime's, there are some very interesting-looking scripts of hers that seem to be lost forever :LZSteary:

I still wish someone chimed in with an idea about storing the chosen action and having it execute after the counterattack :LZSproud:
Well most counter actions are built into battle scripts based on the default counter ability.
Victor Sant - Animated Battlers has it on line 6559 def invoke_counter_attack
but that script has a lot that sets this up.
however for the basic counter options with skills being used Victor Sant also has a counter options script. but you need the base script for it.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-have-a-party-member-counterattack-with-a-specific-skill.182024/