Help with GreatRedSpirit's damage variables script

My apologies for the recent volume of posts, but I keep running into a roadblock every step of the way every script or so.
The following script is supposed to store damage in a variable, however, I cannot get it to store itself within the variable.
ActorDamageIDStart = 1

class Game_Battler < Game_BattlerBase

# Make these available to be read by anyone (and set too just in case)
attr_accessor :hp_damage_last, :hp_damage_turn, :hp_damage_battle

alias :initialize_remember_damage :initialize unless $@
def initialize(*args)
initialize_remember_damage(*args)
# Set our last damage taken arguments to zero
@hp_damage_last = @hp_damage_turn = @hp_damage_battle = 0
end

# When the battler takes damage remember that HP damage
alias :execute_damage_remember_damage :execute_damage unless $@
def execute_damage(user)
# Call the original method
execute_damage_remember_damage(user)

# We want to record damage only, not healing
return if @result.hp_damage <= 0
# Remember this actor's last damage taken, override last value
@hp_damage_last = @result.hp_damage
# Add to the cumulative turn damage here
@hp_damage_turn += @result.hp_damage
# And add to the battle cumulative damage here
@hp_damage_battle += @result.hp_damage
end
end

class Game_Actor < Game_Battler

alias :execute_damage_remember_damage_actor :execute_damage unless $@
def execute_damage(user)
# Call the original method so hp damage is applied correctly
execute_damage_remember_damage_actor(user)

# We want to record damage only, not healing
return if @result.hp_damage <= 0

# We want to remember the damage taken in variables too, do so here
index = (@actor_id - 1) * 3 + ActorDamageIDStart
# Remember this actor's last damage taken, override last value
$game_variables[index + 0] = @hp_damage_last
# Add to the cumulative turn damage here
$game_variables[index + 1] = @hp_damage_turn
# And add to the battle cumulative damage here
$game_variables[index + 2] = @hp_damage_battle
end

end

class Scene_Battle < Scene_Base

#--------------------------------------------------------------------------
# * Battle Start
#--------------------------------------------------------------------------
alias :battle_start_remember_damage :battle_start unless $@
def battle_start
# Call the original method
battle_start_remember_damage
# And wipe everybody's battle-scope damage
$game_party.members.each { |member| member.hp_damage_battle = 0 }
$game_troop.members.each { |member| member.hp_damage_battle = 0 }
end
#--------------------------------------------------------------------------
# * Start Turn
#--------------------------------------------------------------------------
alias :turn_start_remember_damage :turn_start unless $@
def turn_start
# Call the original method
turn_start_remember_damage
# And wipe everybody's turn-scope damage
$game_party.members.each { |member| member.hp_damage_turn = 0 }
$game_troop.members.each { |member| member.hp_damage_turn = 0 }
end

end
I've been trying to call Variable 1, specifically with @hp_damage_last, with even changing the line to
$game_variables[1] = @hp_damage_last
It still returns 0 when called, however. I've called it at end of turn and directly after taking damage (using "Show Text \V[1]" in a troop set) and nothing's changed. So, I feel like I'm missing something within this script.
If it means anything, the current actor I'm testing this on is the 2nd actor in the index, since that 2nd actor requires this script for their gimmick.
It doesn't appear to me the script is doing anything by the actor's index in the party, it's going by actor ID.

# We want to remember the damage taken in variables too, do so here
index = (@actor_id - 1) * 3 + ActorDamageIDStart
You've left ActorDamageIDStart as 1. So do the math for the ID of the actor you're trying to reference, and that's the game variable it's getting stored in.
I tweaked some things a bit so that I could disregard the index entirely. I swapped $game_variables[index + 0] = @hp_damage_last
For
$game_variables[1] = @hp_damage_last
And it still returns 0.

1727198388112.png
1727198410578.png


Alright, I should've prefaced that I was using Yanfly's Battle Engine. Keeping the script after Yanfly's battle engine returns the above screenshots, but putting it before Yanfly's Battle Engine renders all damage pop ups from enemies to be 0, yet properly stores the variable. Am I correct in assuming it would have to slot in somewhere in the middle of Yanfly's script to properly work?
Testing this script and showing results in the console shows that the values you are looking for are saved into the variables only when the actor gets damaged.

If you only want to track the damage the actors do then use this
Ruby:
ActorDamageIDStart = 1

class Game_Battler < Game_BattlerBase

  alias :execute_damage_remember_damage_actor :execute_damage unless $@
  def execute_damage(user)
    # We want to record damage only, not healing
    if @result.hp_damage > 0 && user.is_a?(Game_Actor)
      
      # We want to remember the damage taken in variables too, do so here
      index = (user.id - 1) * 3 + ActorDamageIDStart
      # Remember this actor's last damage taken, override last value
      $game_variables[index + 0] = @result.hp_damage
      # Add to the cumulative turn damage here
      $game_variables[index + 1] += @result.hp_damage
      # And add to the battle cumulative damage here
      $game_variables[index + 2] += @result.hp_damage
    end
    # Call the original method so hp damage is applied correctly
    execute_damage_remember_damage_actor(user)
  end
 
end

class Scene_Battle < Scene_Base

  #--------------------------------------------------------------------------
  # * Battle Start
  #--------------------------------------------------------------------------
  alias :battle_start_remember_damage :battle_start unless $@
  def battle_start
    # Call the original method
    battle_start_remember_damage
    # And wipe everybody's battle-scope damage
    $game_party.members.each { |m| ($game_variables[(m.id - 1) * 3 + ActorDamageIDStart + 1] = 0) }
  end
  #--------------------------------------------------------------------------
  # * Start Turn
  #--------------------------------------------------------------------------
  alias :turn_start_remember_damage :turn_start unless $@
  def turn_start
    # Call the original method
    turn_start_remember_damage
    # And wipe everybody's turn-scope damage
    $game_party.members.each { |m| ($game_variables[(m.id - 1) * 3 + ActorDamageIDStart + 2] = 0) }
  end
 
end

Original thread: https://forums.rpgmakerweb.com/threads/help-with-greatredspirits-damage-variables-script.172126/