[VX ACE] STORING DAMAGE DEALT INTO A VARIABLE?

Posts

Pages: 1
Haven't been lucky trying to find an answer for this one so far, but is there a way to store the damage dealt by an enemy into a variable during a battle? I'm looking to create a skill that uses the number in said variable in its damage formula.
Are you trying to record the damage an enemy dealt or the damage an actor received?
Alright, I'll whip something up. I'll use three variables: Cumulative over battle, cumulative over turn, and last damage received that you can do as you wish. I assume on your gameprofiles this is for Ace then?
Yeah, this is for Ace. Thanks a lot for helping me.
Durf, it's right there in the topic title. Not sure if you want it stored in an actual $game_variables or not so I did it both ways.

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

This will track everybody's hp damage from the last time they took damage. It won't record healing or no-damage actions that targeted a battler. All battlers have this information recorded but when actors take damage the value is stored in a variable. The variable is ID# ActorDamageIDStart in sets of three. The first number is last damage received (reset when taken new damage), the second is damage taken this turn (reset at the start of the next turn), the third is damage taken the entire battle (reset on the start of battle). The variables are read only, changing them won't affect the actors themselves but I can change that if needed. You can access anybody's last damage via hp_damage_last, hp_damage_turn, and hp_damage_battle and change them freely.

Here's a demo project. Fight the two slimes in the first troops with Eric and Natalie. Both have the same three moves that work based on the last damage taken / damage taken this turn / damage taken over the battle (this one even resets itself!).
Nice. I'll test it out this weekend. Would I need to insert this as its own seperate script, or would I need to insert it elsewhere?
Insert as its own script after materials and before main. See the demo project for an example where to put it and how to use it. Yell at me if you see something not working and I'll try to fix it.
It works perfectly. No conflicting scripts or anything of the sort. Now I just need to figure out who in my game could put it to use. Thanks so much, I needed something like this. I'll definetly make sure to credit you in my game.
Max McGee
with sorrow down past the fence
9159
Man, GRS is awesome.
You're just trying to get me to script for you aren't you
Pages: 1