MV can I run a script when switch to next actor?

As the title said.

I used to run a script after an actor's action.

But now I'm using the YEP InstantCast plugin, so when an actor's action ends. This made the script run multiple times during an actor's turn.

I want the script run only once during an actor's turn.
instant skill should run once per turn (twice in a row).
but instant is probably most effective with skill cooldown plugin
so you can use it once, than use another skill and next turn it could
be available or ever 2 turns based how you set it up.
thank you, but maybe i didn't express clearly.

for example, earlier, I made a script to show text "hello" in the endAction phase. In this situation, before the next actor's action, the text would show up.

However, After I used the instantCast plugin, when the actor used an instant item/skill, the text "hello" would also display.

I just want the instant item/skill DO NOT trigger the text.

Is there a way to achieve this?
instant skill should run once per turn (twice in a row).
but instant is probably most effective with skill cooldown plugin
so you can use it once, than use another skill and next turn it could
be available or ever 2 turns based how you set it up.
@ShadowDragon I don't think that is the problem.
the description sounds as if that script is not part of the player decisions, more for some kind of management and as such should only run once per turn after one action, not after every action if the actor has multiple.

@ws6tbz for that, the plugin you're using to run that script needs to be modified.
so yopu need to link us to that plugin and probably the script you're running from it
in the endAction phase. In this situation, before the next actor's action, the text would show up.
always mention all relevant plugins at the very least. Im assuming by endAction youre referring to Yanfly's buffs and states <Custom Action End Effect> notetags?

regardless, the instant cast plugin adds a function to tell if an action is instant to not. since you already have a way to run js on a battler's action, the code to use to see if the action isnt instant is
Code:
if (!user.isInstantCast(user.currentAction().item()))
assuming "user" is a valid reference to the battler in the method youre using
@ShadowDragon I don't think that is the problem.
the description sounds as if that script is not part of the player decisions, more for some kind of management and as such should only run once per turn after one action, not after every action if the actor has multiple.

@ws6tbz for that, the plugin you're using to run that script needs to be modified.
so yopu need to link us to that plugin and probably the script you're running from it

At the begining of battle, a picture would display.
(Sorry I'm really unfamiliar with using script to call image, such as "sprite", "bitmap" ...
So I used the battle event to show picture.)

Then a script would move the picture after every actor/enmemy's action.

Below is my script(plugin) for the requirement

JavaScript:
/*:
 * @plugindesc image moves when an action ends.
 */
var Imported = Imported || {};                
Imported.TestForActionUpdate = true;        
var TesT = TesT || {};                                          
TesT.parameters = PluginManager.parameters('TestForActionUpdate');

var actionCount = 0;

var TesT_startBattle = BattleManager.startBattle;

BattleManager.startBattle = function() {        // initialize the actionCount
    actionCount = 0;
    TesT_startBattle.call(this);
};

var TesT_endAction = BattleManager.endAction;    // move the image after an action ends
BattleManager.endAction = function() {
    actionCount++;
    if(actionCount % 2 == 0) {
        $gameScreen.movePicture(1, 0, 200, 0, 100, 100, 255, 0, 30);    // when the actionCount%2 == 0, move the image to the right
    } else {
        $gameScreen.movePicture(1, 0, -200, 0, 100, 100, 255, 0, 30);    // otherwise, move the image to the left
    }
    TesT_endAction.call(this);
}

Before I used the YEP_InstantCast, the picture can move left and right normally.

But now, the picture does not only move after an action, even after an instant cast(item or skill), the picture would also move.😢
always mention all relevant plugins at the very least. Im assuming by endAction youre referring to Yanfly's buffs and states <Custom Action End Effect> notetags?

regardless, the instant cast plugin adds a function to tell if an action is instant to not. since you already have a way to run js on a battler's action, the code to use to see if the action isnt instant is
Code:
if (!user.isInstantCast(user.currentAction().item()))
assuming "user" is a valid reference to the battler in the method youre using
Thanks, I used the Yanfly's BuffStateCore, but I can't see what's wrong with the plugin.

I tried to look for the flag of "whether actor/enmey used an Instant Cast", in the Yanfly's InstantCast plugin, however I can't find it.
You should have mentioned that you're developing your own plugin for this.

The solution is a bit more complex however.
Basically you need to define and assign a flag to each actor that tells if the extra was already processed for this actor or not.
then a condition that the extra code will only be handled if the flag is not set, setting the flag as part of it.
and then add to the turn start that all those flags are cleared so it works again on the next turn.


That said, your yanfly plugins are not in the correct order. I don't know everyone of them, but the message core needs to be below core but above battlecore. You should check yanfly's list on yanfly.moe for the position of every plugin.
the plugin in my spoiler or yanfly website tells how the correct order is.

but the picture movement is far deeper than simply start and end as you need to see what
function instant cast do and put those alias in your plugin too to do otherwise.

as you need to target more functions as well, as you didn't told about your plugin, you could
try to request one, the plugin(s) you used to have compability between them and a far more
structured code.
Sovled maybe...

JavaScript:
    actionCount++;
    if(actionCount % 2 == 0) {
        $gameScreen.movePicture(1, 0, 200, 0, 100, 100, 255, 0, 30);    // when the actionCount%2 == 0, move the image to the right
    } else {
        $gameScreen.movePicture(1, 0, -200, 0, 100, 100, 255, 0, 30);    // otherwise, move the image to the left
    }

I Encapsulated the code above into a method _movePicture(), and put my plugin before the YEP_InstantCast.js. Then I called the method in the YEP_InstantCast.js.

Original thread: https://forums.rpgmakerweb.com/threads/can-i-run-a-script-when-switch-to-next-actor.174839/