[Yanfly Lunatic States] Use the affected target's stats instead of the caster's

Hello, this is my first post on this forum so I hope I'm in the right spot. I'm using Yanfly's lunatic states script and the punishment add-on, and I'm trying to trigger a poison-style effect where whenever the enemy takes an action, they take damage equal to their max HP. The script makes it really easy to do this based on the caster's stats.

For example, <while effect: MAT slip damage 150%> would make the enemy take damage equal to the caster's magic attack * 150% when they take an action, but what I'm trying to do is base the damage off the enemy's stat instead. Similar to the default poison state included in the RTP, but I want it to trigger per action with the while effect.
Hi! I wrote a small addon to do this, to use it, install it below Yanfly's punishment script.
I did not test it so please tell me if it works on your side.

Ruby:
#==============================================================================
# Yanfly Lunatic States Punishment addon
#------------------------------------------------------------------------------
# Author: Timtrack
# date: 12/08/2025
# Requires: YEA - Lunatic States Package - Punishment v1.01 and
# its required scripts
#==============================================================================
# Description: allows damage (slip damage) to be dealt based on the target
# stats by using MYSTAT instead of STAT (with STAT being MAXHP, MAXMP, ATK, DEF,
# MAT, MDF, AGI, or LUK).
#==============================================================================
# Installation: put it below the required scripts
#==============================================================================

$imported = {} if $imported.nil?
$imported["TIM-YEA-LSP-Punishment-addon"] = true

if $imported["YEA-LunaticStates"]
#==============================================================================
# Game_BattlerBase
#==============================================================================
class Game_BattlerBase
  #--------------------------------------------------------------------------
  # alias method: lunatic_state_extension
  #--------------------------------------------------------------------------
  alias tim_lunatic_state_extension_lspa lunatic_state_extension
  def lunatic_state_extension(effect, state, user, state_origin, log_window)
    case effect.upcase
    #----------------------------------------------------------------------
    # Punish Effect: Target Stat Slip Damage
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    # Best used with close effect. At the end of the turn, the affected
    # battler will take HP slip damage based on its stats. Battler cannot die
    # from this effect.
    #
    # Recommended notetag:
    #   <close effect: stat slip damage x%>
    #
    # Replace "stat" with MYMAXHP, MYMAXMP, MYATK, MYDEF, MYMAT, MYMDF, MYAGI, or MYLUK.
    # Replace x with the stat multiplier to affect damage dealt.
    #
    # This is an addition to the already known SLIP DAMAGE from the punishment addon
    # that worked only with caster's stats, here the damage will be done with the targets's
    # stats as long as you put MYSTAT instead of STAT
    #----------------------------------------------------------------------
    when /(.*)[ ]SLIP DAMAGE[ ](\d+)([%%])/i
      case $1.upcase
      when "MYMAXHP"; dmg = user.mhp
      when "MYMAXMP"; dmg = user.mmp
      when "MYATK";   dmg = user.atk
      when "MYDEF";   dmg = user.def
      when "MYMAT";   dmg = user.mat
      when "MYMDF";   dmg = user.mdf
      when "MYAGI";   dmg = user.agi
      when "MYLUK";   dmg = user.luk
      #when another stat is used like MAXHP etc., will call Yanfly's original script
      else; return tim_lunatic_state_extension_lspa(effect, state, user, state_origin, log_window)
      end
      dmg = (dmg * $2.to_i * 0.01).to_i
      if $imported["YEA-BattleEngine"] && dmg > 0
        text = sprintf(YEA::BATTLE::POPUP_SETTINGS[:hp_dmg], dmg.group)
        user.create_popup(text, "HP_DMG")
      end
      user.perform_damage_effect
      user.hp = [user.hp - dmg, 1].max
    #----------------------------------------------------------------------
    # Stop editting past this point.
    #----------------------------------------------------------------------
    else
      so = state_origin
      lw = log_window
      tim_lunatic_state_extension_lspa(effect, state, user, so, lw)
    end
  end
end # Game_BattlerBase
end # $imported["YEA-LunaticStates"]

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-lunatic-states-use-the-affected-targets-stats-instead-of-the-casters.179370/