Skill that stuns both user and target

Hello, I have a skill that stuns both the spellcaster and the target. The idea behind this skill is that the user is imobilizing the target with her body, so the spellcaster is unable to make any actions while the enemy is stunned. How am I doing this? I use Yanfly's Follow Up Skill script. First, the user casts a skill that stuns the target, then it triggers another skill that stuns the user herself.

But there is a problem. Suppose the enemy has resistance against stun (let's say, 50%). In this situation, there is a chance that the user sucessfully hits the target but is unable to stun it because of its resistance against stun. In this circunstance, the user would stun itself without stunning the target, which does not make sense if you take the concept in account.

What do I want after all? I want the user not to stun itself unless the target is also stunned. Does anyone know how to do this?
Since nobody's replied yet with an easy fix, I'll chime in with something complicated and possibly requiring another script :LZSgrin:

I would do the following through eventing:

1. In the damage formula of the skill, I'd put "v[n]=b.index()" (n being the number of the variable you want to store it in) this will remember which enemy you're targeting. This is where you might need a script because I guess your skill doesn't do any damage, and you don't want it to do any damage, so you have no way to access the damage formula window. You could use this script to bypass that problem.

2. Add a common event to the skill. This will check if the enemy has the stunned state, and if so, will stun the caster. Now if you only have one character that can cast this spell, it's easy, if more than one can do it, you'll need some extra steps.
One caster:
In the common event, put a conditional branch with the condition through script: "$game_troop.members[$game_variables[n]].state?(X)" where X is the ID number of your stun state. This will check if the enemy has the state.
If it's true, then the actor gets the state too (the following should be put in a script window): "$game_party.members[$game_variables[m]].add_state(X)" where "m" is the ID number of the caster. *
If it's false, nothing happens.

Now you probably won't get info in the battle log when you do it like this, so if you want to add that, make another script window and insert this in the conditional branch for true (where I put the *):

SceneManager.scene.log_window.add_text($game_party.members[$game_variables[m]].name +
" is stunned! (or whatever message you want to appear)")
SceneManager.scene.log_window.wait_and_clear

(variable m is the caster's ID, if it's really just one character, you can put their name right in the inverted commas, like: "Jane is stunned!")

If more characters can cast this, then you'll need to add another variable (m) in the damage formula, which will give you who is the caster: v[m]=a.actor_id. The rest (the common event) will be the same.

I'm not sure I explained this well... Ask if you need clarification, or wait a bit until someone replies that this approach is wrong and gives you the better solution :LZSwink:
Since nobody's replied yet with an easy fix, I'll chime in with something complicated and possibly requiring another script :LZSgrin:

I would do the following through eventing:

1. In the damage formula of the skill, I'd put "v[n]=b.index()" (n being the number of the variable you want to store it in) this will remember which enemy you're targeting. This is where you might need a script because I guess your skill doesn't do any damage, and you don't want it to do any damage, so you have no way to access the damage formula window. You could use this script to bypass that problem.

2. Add a common event to the skill. This will check if the enemy has the stunned state, and if so, will stun the caster. Now if you only have one character that can cast this spell, it's easy, if more than one can do it, you'll need some extra steps.
One caster:
In the common event, put a conditional branch with the condition through script: "$game_troop.members[$game_variables[n]].state?(X)" where X is the ID number of your stun state. This will check if the enemy has the state.
If it's true, then the actor gets the state too (the following should be put in a script window): "$game_party.members[$game_variables[m]].add_state(X)" where "m" is the ID number of the caster. *
If it's false, nothing happens.

Now you probably won't get info in the battle log when you do it like this, so if you want to add that, make another script window and insert this in the conditional branch for true (where I put the *):

SceneManager.scene.log_window.add_text($game_party.members[$game_variables[m]].name +
" is stunned! (or whatever message you want to appear)")
SceneManager.scene.log_window.wait_and_clear

(variable m is the caster's ID, if it's really just one character, you can put their name right in the inverted commas, like: "Jane is stunned!")

If more characters can cast this, then you'll need to add another variable (m) in the damage formula, which will give you who is the caster: v[m]=a.actor_id. The rest (the common event) will be the same.

I'm not sure I explained this well... Ask if you need clarification, or wait a bit until someone replies that this approach is wrong and gives you the better solution :LZSwink:
Thank you very much. Actually, my skill does cause damage so I don't really need hime's script. But there is a problem. Your solution only works against the first enemy. For some reason, it does not work against the other enemies. It seems it is not storing enemy id, so it will only work with the monster with the 0 index.
Weird. I use this method with several skills and it works for me. I have to go to sleep now, but I'll have a look at it tomorrow and let you know if I find what might be wrong.
How did you use the variable in the damage formula?
I tried two approaches. First, I used the regular damage formula box:

a.atk * 4 * 0.85; v[82] = b.index()

It didn't cause any damage tho. And I'm almost certain I wrote it wrong.

When I have to set up other things besides damage, I usually do it with Yanfly's Lunatic Damage script, because it's easier . In this second approach, I wrote this:

when /IMOBILIZE/i value += a.atk * 4 * 0.85; $game_variables[82] = b.index();

None of them worked tho.
Try this:

v[82]=b.index() ; a.atk * 4 * 0.85

in the damage formula window. Damage must always be the last number/formula.
Try this:

v[82]=b.index() ; a.atk * 4 * 0.85

in the damage formula window. Damage must always be the last number/formula.
Thank you, it worked nice. I even developed another version of this, but for enemies.

Original thread: https://forums.rpgmakerweb.com/threads/skill-that-stuns-both-user-and-target.153425/