State-based self damage on attack/action

I am trying to figure out how to use yanfly or base code to cause a state to do X amt of damage (percent or otherwise) to an enemy under a state called "Pinned". I have looked into the following:

  • Yanfly Buffs & States
  • Yanfly Act Beg/End
  • Yanfly Skill Core & its associated plugins
  • I've tried (user/battler).gainHp(-x)
  • I've tried endaction recoil (yanfly)

The issue for me is not figuring out which plugin lunatic mode tag line to use (custom confirm/react/etc), its how the code WITHIN the <> needs to look to get it to do what I want. To put simply, I just want a state to do say 50 dmg when the one under that state attempts to do an action. Does anyone have a solve to this either from doing it themselves, or just with their knowledge of the game code? To clarify, I use the term "recoil" but this damage would be independent from the damage that the state-affected battler would cause & the 'recoil' dmg occurs regardless of successful hit
  • I've tried (user/battler).gainHp(-x)
  • I've tried endaction recoil (yanfly)
Those are what would be used to create that effect. the issue with describing what you did is that it doesnt show what you did and where you went wrong. theres many ways to write an affect like that, but they all require a level of precision that cant be verified without seeing how you wrote it.

To put simply, I just want a state to do say 50 dmg when the one under that state attempts to do an action.
Code:
<Custom Action End Effect>
var result = JsonEx.makeDeepCopy(user._result);
user.clearResult();
user.gainHp(-50);
user.startDamagePopup();
user._result = result;
</Custom Action End Effect>

Original thread: https://forums.rpgmakerweb.com/threads/state-based-self-damage-on-attack-action.179835/