MZ Change item description based on current actor state

I'm making a system for my game where crits are telegraphed by the player, or even the enemies, getting a state as their ATB loads, and if they're under the effect of the state their skills are replaced by different more powerful ones.

I also want it to affect items and here comes the difficult part, the only solution I found was to run a common event at the start of each actor's turn and have it replace every item with their crit counterpart and vice-versa, it works but I'm scared it'll just be a lot to process and slow the game down.

My best solution I come up with is to have the item description change based on the state, damage formulas can already use those so it should go hand in hand, but my issue is that I have no idea how you would even do that, javascript evals are disabled in the item description from the database and I can't find a plugin that does what I'm aiming for, any help ?
javascript evals are disabled in the item description from the database and I can't find a plugin that does what I'm aiming for, any help ?
you can use either Yanfly's Message Eval plugin or Waynee95's Eval Text to be able to run JS in the descriptions. I recommend the latter though. its more convenient IMO
thanks, but I am using MZ though
Ah, saw the preferred engine but missed the section. I dont think waynee's plugin should be incompatible offhand after having looked in it a bunch, but i havent tried it in MZ nor looked for stuff thatd break in MZ
yeah no, I'm getting some errors like Uncaught TypeError: Cannot set property 'WindowBase_convertEscapeCharacters' of undefined and Uncaught TypeError: Cannot read property 'indexOf' of undefined this ain't gonna be compatible I think
I think something like this should work as a miniplugin (I haven't tested, but it's similar to my code that makes the description change after using it once, though a bit more complicated):

JavaScript:
Window_Help.prototype.setItem = function(item) {
    let description = "", actor = SceneManager._scene.user();
    if(item) {
        description = item.description;
        let m = null, pat = /<description\[(\d+\)]:([^>]*)>/g;
        do {
            m = pat.exec(item.note);
            if(m && actor.isStateAffected(m[1])) {
                description = m[2];
                break;
            }
        } while(m);
    }
    this.setText(description);
};

Set up your alt descriptions in the note box as follows:

Code:
<description[12]:description if state 12 is applied>
<description[42]:description if state 42 is applied>
etc

You can of course break it over multiple lines. Assuming I got the logic correct, it should go through them all in the order listed and take the first match.
oh my god I need to try this !!!!
I think something like this should work as a miniplugin (I haven't tested, but it's similar to my code that makes the description change after using it once, though a bit more complicated):
damn, I'm getting errors saying that "SceneManager._scene.user is not a function" and the code itself looks red in VisualStudioCode and I don't know why
That was one of the parts I was unsure about. But it certainly is a function in Scene_ItemBase, at least. On the other hand, this code is called in other scenes besides item scenes, so even if that's correct for the item scene I probably need to add some safeguard in case you're in a different scene…

Here's a revised version that adds a safeguard:

JavaScript:
Window_Help.prototype.setItem = function(item) {
    let description = "";
    if(item) {
        description = item.description;
        if(SceneManager._scene instanceof Scene_ItemBase) {
            let actor = SceneManager._scene.user();
            let m = null, pat = /<description\[(\d+\)]:([^>]*)>/g;
            do {
                m = pat.exec(item.note);
                if(m && actor.isStateAffected(m[1])) {
                    description = m[2];
                    break;
                }
            } while(m);
        }
    }
    this.setText(description);
};
really really strange things are happening with that plugin, I'm quite confused and deeply sorry to bother you with my issues but what even is going on here
Turns out I just misplaced one \. Can you spot the difference? 😉

JavaScript:
Window_Help.prototype.setItem = function(item) {
    let description = "";
    if(item) {
        description = item.description;
        if(SceneManager._scene instanceof Scene_ItemBase) {
            let actor = SceneManager._scene.user();
            let m = null, pat = /<description\[(\d+)\]:([^>]*)>/g;
            do {
                m = pat.exec(item.note);
                if(m && actor.isStateAffected(m[1])) {
                    description = m[2];
                    break;
                }
            } while(m);
        }
    }
    this.setText(description);
};
yeah no it doesn't work and I don't know why, I tried it on the overworld with everyone affected, tried it in battle, no result it's wack, and yes I did setup the description in the notebox as you said, very weird
Ohhh, the safeguard I added would make it only work on the map, if at all… do you see anything at all in the developer console? After launching the game, press F8, switch to the Console tab, and check if there's an error message. It wouldn't be too hard to also make it work in battle, but it's probably better to get it working on the map first.
well it's only really ever gonna be used in battle I think, but I still tried what you advised and there's nothing going on in the console weirdly enough
I found some time to test it out and found the issue. Try this:

JavaScript:
Window_Help.prototype.setItem = function(item) {
    let description = "";
    if(item) {
        description = item.description;
        let actor = null;
        if(SceneManager._scene instanceof Scene_ItemBase) {
            actor = SceneManager._scene.user();
        } else if(SceneManager._scene instanceof Scene_Battle && BattleManager.inputtingAction()) {
            actor = BattleManager.inputtingAction().subject();
        }
        if(actor) {
            let m = null, pat = /<description\[(\d+)\]:([^>]*)>/g;
            do {
                m = pat.exec(item.note);
                if(m && actor.isStateAffected(Number(m[1]))) {
                    description = m[2];
                    break;
                }
            } while(m);
        }
    }
    this.setText(description);
};

I also added the logic that should allow it to work in battle (I haven't tested that part though).
IT WORKS !!! AHAH THANK YOU SO MUCH MAN

Original thread: https://forums.rpgmakerweb.com/threads/change-item-description-based-on-current-actor-state.183538/