Script that allows a state to take incoming damage it prevents and instead put it into a variable?

Awhile back, I made a thread in a different sub-forum asking how to make a skill that absorbs all incoming damage and puts that absorbed damage into a variable (here). The only reply I got to it suggested I'd need a script that would allow states to count damage taken and store it into a variable.

I put off posting a script request for such a script because I figured I'd get around to polishing my game's various classes later, once I had finished them. However, due to a circumstance I had not taken into account, I'd had to start the clean-up and polishing now. And part of that clean-up means tying up loose-ends I left-- such as figuring out a solution to this problem of mine.

So, is there a script floating around (preferably one that doesn't require a "core engine" or any of that nonsense) that can accomplish this; and if not, would anyone be willing to make a script that does?
preferably one that doesn't require a "core engine" or any of that nonsense
Calling core scripts "nonsense" is not exactly a good way to describe them. They store useful methods and make them accessible to any other script you might want to use. It is a very efficient way to save sloc (Source Lines Of Code).

That said, what you are trying to achieve is fairly simple.
Code:
class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # * Calculate Damage
  #--------------------------------------------------------------------------
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    if state?(STATE_ID_GOES_HERE)
      $game_variables[VARIABLE_ID_GOES_HERE] = value
      value = 0
    end
    @result.make_damage(value.to_i, item)
  end
end

This will store damage inside the variable so you can use that value whenever you need it. On top of it, it reduces the damage taken to 0 when the state is applied. It should do what you are looking for.
Calling core scripts "nonsense" is not exactly a good way to describe them.

Sorry about that.

That said, what you are trying to achieve is fairly simple.
Code:
class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # * Calculate Damage
  #--------------------------------------------------------------------------
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    value *= mdr if item.magical?
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    if state?(STATE_ID_GOES_HERE)
      $game_variables[VARIABLE_ID_GOES_HERE] = value
      value = 0
    end
    @result.make_damage(value.to_i, item)
  end
end

This will store damage inside the variable so you can use that value whenever you need it. On top of it, it reduces the damage taken to 0 when the state is applied. It should do what you are looking for.

Thank you so much!

Original thread: https://forums.rpgmakerweb.com/threads/script-that-allows-a-state-to-take-incoming-damage-it-prevents-and-instead-put-it-into-a-variable.112856/