MV RMMV State Duration Based On Variable?

Without going into too much detail, I want to give my players the ability to apply a debuff to enemies. And how long that debuff lasts, is based on a variable. Also, the variable will be changing constantly, but I want the duration to be based on what the variable was at the time the state was applied.

(If you must know, said variable is how well they performed an action command. I'm using SomeRandomDude's Timed Attack System series of plugins.)

(Also, I want every status effect duration to be based on the Timed Attack results, if it's important.)
you could do it with Yanfly's buffs and states plugin easily. youd just give that state a notetag with an apply effect to set its own duration to that variable's value.

Code:
<Custom Apply Effect>
user.setStateTurns(stateId, $gameVariables.value(x))
</Custom Apply Effect>
just replace the x with the variable's id assuming it writes the value to a game variable.
you could do it with Yanfly's buffs and states plugin easily. youd just give that state a notetag with an apply effect to set its own duration to that variable's value.

Code:
<Custom Apply Effect>
user.setStateTurns(stateId, $gameVariables.value(x))
</Custom Apply Effect>
just replace the x with the variable's id assuming it writes the value to a game variable.
Thanks.

Original thread: https://forums.rpgmakerweb.com/threads/rmmv-state-duration-based-on-variable.174545/