MV Follow-Up Attack when enemy is afflicted with a state help

Hello! First off I'd like to apologize if I'm posting this in the wrong area or something, its my first time posting on the forum 🙂

I have a character called Robbie, who inflicts a state called Destabilized on enemies. I want it so that when an ally hits an enemy with the Destabilized state, Robbie launches his follow-up attack onto that enemy. I understand the basics of what I'm trying to do but I can't seem to get it to work via scripts (which is how I'd like to do it to avoid having to paste a common event into every single skill in my database.

My JS knowledge is very very limited, so I asked chatGPT to help me hoping that it would be a simple enough task for it to handle, and this is what I have


JavaScript:
if ($gameTroop.members().some(enemy => enemy === target && enemy.isStateAffected(24))) {

    $gameTemp.reserveCommonEvent(7);

}

and I have it under the Battle Events Page like so:
Spoiler: Battle Event Image
1731372604957.png

The Common Event that I am running is simply a Force Action event:

Spoiler: Common Event
1731372662220.png

If someone could help me, I'd really appriciate it!!!!
I'd like to apologize if I'm posting this in the wrong area or something
There's no need to apologize to anyone; it would go in Plugin Requests, which is not a problem. However:
My JS knowledge is very very limited, so I asked chatGPT to help me
It's against the rules to ask for help correcting AI code. Largely because:
hoping that it would be a simple enough task for it to handle
There's almost no such thing. AI generators generate things, they make things up. Code can't function if it's made up. That's why humans learn how to do it.

In the example you give, it's done in completely the wrong way (troop event) with completely the wrong code (there's no such thing as target).

You should be using a plugin like Yanfly's Buffs & States to do the force action script call when the battler with the state gets hit.
There's no need to apologize to anyone; it would go in Plugin Requests, which is not a problem. However:

It's against the rules to ask for help correcting AI code. Largely because:

There's almost no such thing. AI generators generate things, they make things up. Code can't function if it's made up. That's why humans learn how to do it.

In the example you give, it's done in completely the wrong way (troop event) with completely the wrong code (there's no such thing as target).

You should be using a plugin like Yanfly's Buffs & States to do the force action script call when the battler with the state gets hit.
My bad! I didn't know that was a rule.

I wasn't trying to edit the AI Code, I knew that it was wrong since I figured it would be hard for an AI to understand the library of RPG Maker (if that's even the right way of putting it), I just thought the code may give a better understanding of what I was trying to accomplish.😅

I am using Buffs and States Core, but the main problem is that I can only get the follow-up to function once per turn and I'm using Yanfly's CTB battle system (only casts once all allies + all enemies take action.) I think I'm pretty close to figuring it out, Thank you!
So I don't know what your criteria are for "hit" - if it's just physical skills, anything anyone does to damage the enemy, etc.

But on a basic level, you'd do something like this in the state. I'm pretending Robbie is actor ID 1.

Code:
<Custom Respond Effect>
// Is the attacker NOT Robbie?
if (user.actorId() != 1)
{
// Make Robbie attack
    $gameActors.actor(1).forceAction(1, target.index());
    BattleManager.forceAction($gameActors.actor(1));
}
</Custom Respond Effect>

When you get into talking about the CTB and stuff, the risk can be that using force action might take up that battler's next actual action; so you might have to do something like incorporating this into an action sequence.

But this ought to do something.
So I don't know what your criteria are for "hit" - if it's just physical skills, anything anyone does to damage the enemy, etc.

But on a basic level, you'd do something like this in the state. I'm pretending Robbie is actor ID 1.

Code:
<Custom Respond Effect>
// Is the attacker NOT Robbie?
if (user.actorId() != 1)
{
// Make Robbie attack
    $gameActors.actor(1).forceAction(1, target.index());
    BattleManager.forceAction($gameActors.actor(1));
}
</Custom Respond Effect>

When you get into talking about the CTB and stuff, the risk can be that using force action might take up that battler's next actual action; so you might have to do something like incorporating this into an action sequence.

But this ought to do something.
OH MY GOSH THIS WORKED EXACTLY HOW I WANTED!!! thank you so much I've been struggling with this for two days 😢

So I don't know what your criteria are for "hit" - if it's just physical skills, anything anyone does to damage the enemy, etc.

But on a basic level, you'd do something like this in the state. I'm pretending Robbie is actor ID 1.

Code:
<Custom Respond Effect>
// Is the attacker NOT Robbie?
if (user.actorId() != 1)
{
// Make Robbie attack
    $gameActors.actor(1).forceAction(1, target.index());
    BattleManager.forceAction($gameActors.actor(1));
}
</Custom Respond Effect>

When you get into talking about the CTB and stuff, the risk can be that using force action might take up that battler's next actual action; so you might have to do something like incorporating this into an action sequence.

But this ought to do something.
One extra thing actually-- I have a skill type in my game called "followup" reserved for any followup attack. is there a way I could check if the damage is NOT followup type just so that the player doesn't have followup attacks triggering each other endlessly?

I tried editing the code, but it didn't work for me.
JavaScript:
<Custom Respond Effect>

// Is the attacker NOT Robbie?

if (user.actorId() != 22){

if (skill.stypeId() !=5)

{

// Make Robbie attack

    $gameActors.actor(22).forceAction(50, target.index());

    BattleManager.forceAction($gameActors.actor(22));

}}

</Custom Respond Effect>

I wrote if (skill.stypeId != 5) but that just stopped the followup from triggering at all. I imagine I'm not supposed to use "skill" but I couldn't find out how to write this looking through the RPG maker library.
I wrote if (skill.stypeId != 5) but that just stopped the followup from triggering at all.
making random guesses rarely gets you where you need to be. not saying you cant, but there should be no expectation that it should work without a reason to.
When playing around with JS, its a good habit to have the devtools console open to check for errors. there is no skill variable within that tag, so youd get an error for trying to get the stypeId of undefined. the console would have said it. because of that error, the rest of the notetag wouldnt run.

I couldn't find out how to write this looking through the RPG maker library
its not the only resource youd need in this case. once you start dealing with stuff introduced by plugins, youd also have to be mindful of what the plugin says and does either by reading the documentation or looking into the plugin itself if the documentation is lacking.

respond effects are ran from the Game_Action triggering it, so you would want to do something like
Code:
if (user.actorId() != 22 && this.item().stypeId!=5){
    // Make Robbie attack
    $gameActors.actor(22).forceAction(50, target.index());
    BattleManager.forceAction($gameActors.actor(22));
}
making random guesses rarely gets you where you need to be. not saying you cant, but there should be no expectation that it should work without a reason to.
When playing around with JS, its a good habit to have the devtools console open to check for errors. there is no skill variable within that tag, so youd get an error for trying to get the stypeId of undefined. the console would have said it. because of that error, the rest of the notetag wouldnt run.


its not the only resource youd need in this case. once you start dealing with stuff introduced by plugins, youd also have to be mindful of what the plugin says and does either by reading the documentation or looking into the plugin itself if the documentation is lacking.

respond effects are ran from the Game_Action triggering it, so you would want to do something like
Code:
if (user.actorId() != 22 && this.item().stypeId!=5){
    // Make Robbie attack
    $gameActors.actor(22).forceAction(50, target.index());
    BattleManager.forceAction($gameActors.actor(22));
}
I know 😢I have very very little js knowledge, and coding knowledge in general.
I am going to be taking classes soon on it for my compsci minor, but I tried to just piece together things from the code he sent and form my own solution before asking for help.

Also, your code worked perfectly! Thank you so much, you all have been a big help 🙂

Original thread: https://forums.rpgmakerweb.com/threads/follow-up-attack-when-enemy-is-afflicted-with-a-state-help.173170/