How to change the target of an attack mid-action

Hello, thanks in advance for your attention.

I would like to know if there is a way to change the target of an action after an enemy has selected their original target, but before the action resolves.

For context, I am trying to create a function similar to Guard from Darkest Dungeon, where certain abilities can redirect attacks from one target to another. It behaves similar to Substitute, except it is unconditional, and applies only to a single target.

I own most VisuStella plug-ins, and I am willing to buy more if the solution can be found within one.

Thank you for your time, and have a nice day.
There are a number of ways, amongst the various state notetags on offer.

But the Aggro Control System plugin doesn't do what you want by itself?
There are a number of ways, amongst the various state notetags on offer.

But the Aggro Control System plugin doesn't do what you want by itself?
I can work with both notetags and scripts, but I wasn't able to find one myself. The closest things I found were setting this._targetIndex to the ID I wanted to steer the attack to, and the plugin command TARGET: Current Index from BattleCore, but I wasn't able to get them to work - though I might be using them wrong.

I use Aggro Control for other reasons, but it doesn't quite solve this particular need. It only works on actors as far as I know, and the mechanics are different. Let me know if providing more context information can be useful.

Thank you for your time!
I can work with both notetags and scripts, but I wasn't able to find one myself. The closest things I found were setting this._targetIndex to the ID I wanted to steer the attack to, and the plugin command TARGET: Current Index from BattleCore, but I wasn't able to get them to work - though I might be using them wrong.
It would be helpful if you showed what you had tried that didn't work.

I use Aggro Control for other reasons, but it doesn't quite solve this particular need. It only works on actors as far as I know, and the mechanics are different.
The instructions say "Provoke and taunt effects work both ways for actors and enemies."

So from your description, it's unclear how this isn't solved by giving a state with <Taunt> to all actors except the guarded one.
Here is the script that I was trying to use inside an action sequence from BattleCore:
1679065914964.png

The state ID 40 is a state that has no effect other than establishing a character is guarded.
The conditional branch checks if the target is guarded.
The guard identify is irrelevant, it's just a check I use for other functions.
And the two commands underneath were my attempts to steer the target. The number 1 is a placeholder, I have a function to determine the index of the character who's guarding but I didn't include it there for ease of reading. That being said, once the enemy targets the guarded battler, nothing happens; the attack resolves targeting the guarded battler anyway.

Here is an example of the way I would like this to work: Let's say there are four battlers on the same team named Aaron, Bart, Charles and Daniel. If Aaron decides to guard Bart, all attacks directed towards Bart would be redirected towards Aaron, but attacks directed towards Aaron, Charles and Daniel would be unaffected. If then Charles decided to guard Daniel, attacks aiming at Daniel would be steered towards Charles, attacks directed at Bart would be steered towards Aaron, and attacks agains Aaron and Bart would be unaffected.

Applying a Taunt status globally wouldn't work quite the same, because it would entirely prevent a battler from targeting the guarded battlers, rather than redirecting the attack (which may sound functionally identical, and I do see your point, but I liked the idea of the attack being redirected afterwards because it allowed me to play with the interaction of guarding itself, like making a cool animation in which the guarding character jumps in front of the guarded one, or mechanics that trigger specifically when an attack is redirected), and would not allow for multiple guards to exist at the same time. I guess I could make a function that checks the whole party, applies Taunt to those who are guarding and not to those who are being guarded, but again this would not really redirect the attack, just prevent a battler from targeting the guarded battler at all. It would also change the mathematics of the probability of a character being targeted.

Thank you for your patience, and I apologize if I wasn't clear enough at first.
Here is the script that I was trying to use inside an action sequence from BattleCore:
One problem with this is that you would have to copy this into every action sequence for every skill that an enemy can use in your entire game. And then if there's anything else you add to your game later that can also affect targeting, it also has to get hard coded into every skill like this.

I also think the BattleManager stuff is more complicated than it needs to be, don't action sequences provide you with a target variable?

My experience with trying to actually change the target of a skill during its execution via code is that it's very problematic. Maybe someone else will be able to offer better advice, but I haven't been able to get it to work.

Applying a Taunt status globally wouldn't work, because it would entirely prevent a battler from targeting the guarded battlers, rather than redirecting the attack (which may sound functionally identical, and I do see your point
That was indeed my point 😉

but I liked the idea of the attack being redirected afterwards because it allowed me to play the interaction of guarding itself, like making a cool animation in which the guarding character jumps in front of the guarded one, or mechanics that trigger specifically when an attack is redirected)
That's reasonable.

and would not allow for multiple guards to exist at the same time.
It could.

You could add a variable to the guarded actor. So your skill might do something like:
Code:
<JS Post-Apply>
user.addState(X); // X is the ID of a state with Taunt
target.guardedBy=user;
</JS Post-Apply>

You could also check out this plugin. It's a little convoluted to follow the directions, but you can structure a state to cause a specific actor to substitute for another specific actor.
One problem with this is that you would have to copy this into every action sequence for every skill that an enemy can use in your entire game. And then if there's anything else you add to your game later that can also affect targeting, it also has to get hard coded into every skill like this.
I think I am fine with this, I can code it into a common event and place it at the beginning of each action sequence, and if the need arises, just edit the common event. But thank you for highlighting it! I don't think it's a problem anyway.

I also think the BattleManager stuff is more complicated than it needs to be, don't action sequences provide you with a target variable?
I looked for one, but couldn't find it. I tried this plugin command:
1679069434951.png

However, nothing happens, and the attack hits the original target anyway. I might be using it wrong though.

Can you tell me more about the target variable? I would love if it was as simple as setting it to the index of the guarding character. I couldn't quite find it among the settings of BattleCore.

You could add a variable to the guarded actor. So your skill might do something like:
Code:
<JS Post-Apply>
user.addState(X); // X is the ID of a state with Taunt
target.guardedBy=user;
</JS Post-Apply>
This could work as a last resort, but I would still prefer to avoid using Taunt. Although, what is the "target.guardedBy=user;" line? Any chance that one can be used by itself?

You could also check out this plugin.
I will definitely check it out if I can't manage to do it with the target variable or BattleManager.

Thank you for all the suggestions, really.
I looked for one, but couldn't find it. I tried this plugin command:...Can you tell me more about the target variable?
Sorry, I assumed since your action sequence involved a fairly complex script call that you had some coding knowledge, so I was using terminology at that level.

I just mean the ability to use the word target to refer to the target, like you can in the various skill and state notetags. Looking at VisuStella Core Engine, it's actually prepended with a dollar sign, so you should be able to simply do
Code:
Conditional Branch -> Script -> $target.isStateAffected(40)

This could work as a last resort, but I would still prefer to avoid using Taunt. Although, what is the "target.guardedBy=user;" line?
That is, as I said, adding a variable to the actor you targeted with the skill. You might want to read through Yanfly's Tips & Tricks, that's a technique he uses a lot. You can also find a thread by Trihan that adapts them to VisuStella notetags.

So once it's on there you can reference it from any code anyplace that's looking at that actor and have direct access to the actor who is guarding them.
Code:
Conditional Branch -> Script -> $target.isStateAffected(40)
Oh yeah, this is smoother. Thank you.

I will check it out. My knowledge of Java is limited, and mostly referenced from this document here. I am mostly learning it for the sake of RPG Maker.

Anyway, I get that there is no known way to change the target of an attack mid-action with either action sequences or Java scripts? Not to come off as ungrateful, I just want to check if my original idea is possible before I modify the mechanics by using taunts or the substitute plugin.

Thank you anyway for the support.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-change-the-target-of-an-attack-mid-action.155888/