Weakness/Critical Hit Boosts for the attacker.

Hello all, I have a question about arranging a global passive using Yanfly's Auto-Passives plugin.


I have used this plugin successfully in the past but I am having some trouble writing a particular code.
In wholeness; I wish to reward both players and enemies for striking weaknesses/landing critical hits by applying a state on the user that essentially increases their next attack's damage output by 15% and reduces their MP/HP Costs by 15%. Think of it in a similar vein to the "Smirk" system in SMT. It's also a state that wears off in 1 turn, regardless of action.

I know this seems easy but I have been troubled with actually getting the system to work. I tried this:
(also, the "55" is the "Smirk" state identifier)

<Custom Confirm Effect>

if (this.isHpEffect() && value > 0)

var elements = this.getItemElements();

for (var i = 0; i < elements.length; ++i)

var elementId = elements;

if (target.elementRate(elementId) > 1.00) {

a.addState(55)

break;

</Custom Confirm Effect>

but i feel like it's a bit wonky and all over the place. I personally think I don't have a good handle on writing up this kinda stuff, so if anyone can tell me what they see is the problem I'd love to hear it.

Also noted: This code doesn't have the critical hit variant included. I haven't gotten to that part yet, but if anyone notes of a good way to include that I'm all ears. Thank you for taking the time to consider all this, I know it's a bit of a handful X_X
<Custom Establish Effect>

// Check if the attack is a physical attack that dealt HP damage from a critical hit.

if (this.isPhysical() && target.result().hpDamage > 0 && target.result().critical) {

user.gainTp(5);

target.addState(58);

}

</Custom Establish Effect>
This passive state is attached to my physical characters by default. Anytime they land a critical strike with any ability that deals physical damage, they gain an additional 5 TP and the target receives a state.

Original thread: https://forums.rpgmakerweb.com/threads/weakness-critical-hit-boosts-for-the-attacker.118984/