MZ More SV Motions for States

Is there any free plugins that allow you to use other SV Motions with states?

What I'm looking for is to have certain states change the SV Motion of the enemy when they have it. Currently the only options the engine gives is Dead, Abnormal, Normal, and Sleep. I want to be able to use the others like escape, victory, ect. I am adding the status ailments to the animated sv sprite sheets for enemies since I cannot find a plugin that makes normal one's work with enemies, that functions.
This might work (untested):
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc Use other motions for states.
 * @help State notetag:
 *     <motion: X>
 * Replace X with the name of a valid motion:
 *     walk      wait      chant     guard
 *     damage    evade     thrust    swing
 *     missile   skill     spell     item
 *     escape    victory
 * E.g. <motion: victory>
 */
void (alias => {
  const TAG_NAME = "motion";
  Scene_Boot.prototype.start = function() {
    alias.apply(this, arguments);
    const S = $dataStates;
    for (let n = S.length; --n;) {
      const name = String(S[n].meta[TAG_NAME]).trim().toLowerCase();
      if (name) {
        const ix = Sprite_Actor.MOTIONS[name]?.index;
        if (ix)
          S[n].motion = ix;
      }
    }
  };
})(Scene_Boot.prototype.start);
Thanks a lot for this. I tested it out and it is not changing the sv motions.
Ah, OK, I see the problem: the sprite has its own order for motion priority and doesn't check non-standard values. Try this code instead:
Spoiler: plugin code v2
JavaScript:
/*:
 * @target MZ
 * @plugindesc Use other motions for states.
 * @help State notetag:
 *     <motion: X>
 * Replace X with the name of a valid motion:
 *     walk      wait      chant     guard
 *     damage    evade     thrust    swing
 *     missile   skill     spell     item
 *     escape    victory
 * E.g. <motion: victory>
 *
 * Free to use and/or modify for any project, no credit required.
 */
void (alias => {

    /** Name used for the plugin's notetag. */
    const TAG_NAME = "motion";

    // Update state motion values for tagged states.
    Scene_Boot.prototype.start = function() {
        alias.apply(this, arguments);
        const S = $dataStates;
        for (let n = S.length; --n;) {
            const name = String(S[n].meta[TAG_NAME]).trim().toLowerCase();
            if (name) {
                const ix = Sprite_Actor.MOTIONS[name]?.index;
                if (ix)
                    S[n].motion = ix;
            }
        }
    };

})(Scene_Boot.prototype.start);

void (alias => {

    /**
     * @param {number} index motion index
     * @returns {string} corresponding motion name.
     */
    const getMotionName = function(index) {
        const S = Sprite_Actor.MOTIONS;
        for (const k of Object.keys(S))
            if (S[k].index === index)
                return k;
        return '';
    };

    /**
     * @param {Game_Actor} actor reference actor
     * @param {string} motionName custom motion name
     * @returns {boolean} `true` iff the custom motion should show.
     */
    const shouldDoCustomStateMotion = function(actor, motionName) {
        // various motions are checked in order of importance
        // this function decides how important the custom state motion is
        // the comments are the default motions
        if (actor.isInputting() || actor.isActing())
            return false;   // walk
        // ---------------- // dead (state)
        // ---------------- // sleep (state)
        if (actor.isChanting())
            return false;   // chant
        if (actor.isGuard() || actor.isGuardWaiting())
            return false;   // guard
        return true;    // <- allow a custom state motion if you get here
        // ---------------- // abnormal (state)
        if (actor.isDying())
            return false;   // dying
        if (actor.isUndecided())
            return false;   // walk
        return false;       // wait
    };

    // Refresh to a custom state motion if appropriate.
    Sprite_Actor.prototype.refreshMotion = function() {
        alias.apply(this, arguments);
        const actor = this._actor;
        if (actor) {
            const index = actor.stateMotionIndex();
            const mName = getMotionName(index);
            if (shouldDoCustomStateMotion(actor, mName))
                this.startMotion(mName);
        }
    };

})(Sprite_Actor.prototype.refreshMotion);
I did a quick test with <motion: victory> on the default Poison state and this one seemed to work OK for me with no other plugins active.

It's set up so that all custom state motions all have priority 1 step above the default "abnormal" state motion. The shouldDoCustomStateMotion function decides the relative priority of different motions, in case you want to change that.
Thank you again for the update. I can get it to work on the player just fine but it doesn't seem to be working on enemies. Is that possible to make it work on enemies that are using sv sprite sheets?
Sorry, I glossed over that. What plugin are you using to assign animated battlers to enemies? If it's not borrowing from the existing code on Sprite_Actor then any motion adjustment will have to be done based on the plugin's code.
I'm using VS Battlecore, which is probably an issue since they scramble their code.

Battlecore does use motion as a tag to set what standby motion you want them to have. I don't know as much about js as I would like but, would notetags conflict even if they are on different note (like enemy and state)?
Notetags are literally just text, it's what the plugin does with that text that matters.

It looks like VisuStella has a paid add-on for custom state motions: Visual State Effects. 👋
Yeah I was hoping to avoid that. I wonder if there is a way to have the state overlays work on enemies
You can rename my plugin's notetag by editing this line:
JavaScript:
    const TAG_NAME = "motion";
I suspect that won't fix the problem, though.

Original thread: https://forums.rpgmakerweb.com/threads/more-sv-motions-for-states.153453/