Elemental Efficiency Text Pop-Up

So I basically figured out how to change the text for "Critical". I would like to have Text-Pop ups based on Element Efficiency.

Code:
class RPG::Sprite
  def damage(value, critical)
    dispose_damage
    if value.is_a?(Numeric)
      damage_string = value.abs.to_s
    else
      damage_string = value.to_s
    end
    bitmap = Bitmap.new(160, 48)
    bitmap.font.name = "Consolas"
    bitmap.font.size = 32
    bitmap.font.color.set(0, 0, 0)
    bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
    bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
    bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
    bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
    if value.is_a?(Numeric) and value < 0
      bitmap.font.color.set(176, 255, 144)
    else
      bitmap.font.color.set(255, 255, 255)
    end
    bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
    if critical
      bitmap.font.size = 20
      bitmap.font.color.set(0, 0, 0)
      bitmap.draw_text(-1, -1, 160, 20, "GET SMACKED", 1)
      bitmap.draw_text(+1, -1, 160, 20, "GET SMACKED", 1)
      bitmap.draw_text(-1, +1, 160, 20, "GET SMACKED", 1)
      bitmap.draw_text(+1, +1, 160, 20, "GET SMACKED", 1)
      bitmap.font.color.set(255, 255, 255)
      bitmap.draw_text(0, 0, 160, 20, "GET SMACKED", 1)
    end
    @_damage_sprite = ::Sprite.new(self.viewport)
    @_damage_sprite.bitmap = bitmap
    @_damage_sprite.ox = 80
    @_damage_sprite.oy = 20
    @_damage_sprite.x = self.x
    @_damage_sprite.y = self.y - self.oy / 2
    @_damage_sprite.z = 3000
    @_damage_duration = 40
  end
end

Now by logic I think I need to set up new " attr_accessor" in Game_Battler 1 probably called (or similar):
Code:
attr_accessor :a_damage
attr_accessor :b_damage
attr_accessor :c_damage
attr_accessor :d_damage
attr_accessor :e_damage
attr_accessor :f_damage

My issue is that I can't find the source of the damage calculaton and how to link those together.

In Game_Enemy the calculation happens in the table:
Code:
  def element_rate(element_id)
    # Get a numerical value corresponding to element effectiveness
    table = [0,200,150,100,50,0,-100]
    result = table[$data_enemies[@enemy_id].element_ranks[element_id]]
    # If protected by state, this element is reduced by half
    for i in @states
      if $data_states[i].guard_element_set.include?(element_id)
        result /= 2
      end
    end
    # End Method
    return result
  end

How do I link the table to a new attr_accessor so I can call it on my class RPG::Sprite Class?
To answer your question about where the calculation happens - it's in Game_Battler 3 (Game_Battler 1,2, and 3 are actually all the same class just spread across three entries in the script editor).

So to achieve what you want, I would find where the `damage` method from RPG::Sprite is called from then you can modify both the method and its calls. A brief investigation shows that it's called from Sprite_Battler's `update` method (it may be called from other places. I wasn't super thorough). Then your changes look something like this:

Ruby:
class RPG::Sprite
  def damage(value, critical, element_rate) # NEW parameter
      # YOUR CHANGES HERE
  end
end

class Sprite_Battler < RPG::Sprite
    def update
        # Original Code
        # Damage
        if @battler.damage_pop
            damage(@battler.damage, @battler.critical, @battler.element_rate)
            @battler.damage = nil
            @battler.critical = false
            @battler.element_rate = nil
            @battler.damage_pop = false
        end
        # More code
    end
end

class Game_Battler
    attr_accessor :element_rate
    alias original_elements_correct elements_correct
    def elements_correct(element_set)
        @element_rate = original_elements_correct(element_set)
        return @element_rate
    end
end

Please keep in mind this is just a rough idea. I threw this together so it likely has mistakes and errors but hopefully it gets you pointed in the right direction.
To answer your question about where the calculation happens - it's in Game_Battler 3 (Game_Battler 1,2, and 3 are actually all the same class just spread across three entries in the script editor).

So to achieve what you want, I would find where the `damage` method from RPG::Sprite is called from then you can modify both the method and its calls. A brief investigation shows that it's called from Sprite_Battler's `update` method (it may be called from other places. I wasn't super thorough). Then your changes look something like this:

Ruby:
class RPG::Sprite
  def damage(value, critical, element_rate) # NEW parameter
      # YOUR CHANGES HERE
  end
end

class Sprite_Battler < RPG::Sprite
    def update
        # Original Code
        # Damage
        if @battler.damage_pop
            damage(@battler.damage, @battler.critical, @battler.element_rate)
            @battler.damage = nil
            @battler.critical = false
            @battler.element_rate = nil
            @battler.damage_pop = false
        end
        # More code
    end
end

class Game_Battler
    attr_accessor :element_rate
    alias original_elements_correct elements_correct
    def elements_correct(element_set)
        @element_rate = original_elements_correct(element_set)
        return @element_rate
    end
end

Please keep in mind this is just a rough idea. I threw this together so it likely has mistakes and errors but hopefully it gets you pointed in the right direction.

Thank you very much but I think that in general that made me even more confused.

By Logic it should be Called during the damage step not in a new class. The calculations are done by the system to determine if or not a multiplyer is set. The resulting output is delt in increased or decreased damage for example.

I'll look more into it tomorrow probably but thank you for a nudge in a direction
This is an extract of Sprite_Battler class:

Ruby:
class Sprite_Battler
  def update
    super
    # If battler is nil
    if @battler == nil
      self.bitmap = nil
      loop_animation(nil)
      return
    end
    # If file name or hue are different than current ones
    if @battler.battler_name != @battler_name or
       @battler.battler_hue != @battler_hue
      # Get and set bitmap
      @battler_name = @battler.battler_name
      @battler_hue = @battler.battler_hue
      self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue)
      @width = bitmap.width
      @height = bitmap.height
      self.ox = @width / 2
      self.oy = @height
      # Change opacity level to 0 when dead or hidden
      if @battler.dead? or @battler.hidden
        self.opacity = 0
      end
    end
    # If animation ID is different than current one
    if @battler.damage == nil and
       @battler.state_animation_id != @state_animation_id
      @state_animation_id = @battler.state_animation_id
      loop_animation($data_animations[@state_animation_id])
    end
    # If actor which should be displayed
    if @battler.is_a?(Game_Actor) and @battler_visible
      # Bring opacity level down a bit when not in main phase
      if $game_temp.battle_main_phase
        self.opacity += 3 if self.opacity < 255
      else
        self.opacity -= 3 if self.opacity > 207
      end
    end
    # Blink
    if @battler.blink
      blink_on
    else
      blink_off
    end
    # If invisible
    unless @battler_visible
      # Appear
      if not @battler.hidden and not @battler.dead? and
         (@battler.damage == nil or @battler.damage_pop)
        appear
        @battler_visible = true
      end
    end
    # If visible
    if @battler_visible
      # Escape
      if @battler.hidden
        $game_system.se_play($data_system.escape_se)
        escape
        @battler_visible = false
      end
      # White flash
      if @battler.white_flash
        whiten
        @battler.white_flash = false
      end
      # Animation
      if @battler.animation_id != 0
        animation = $data_animations[@battler.animation_id]
        animation(animation, @battler.animation_hit)
        @battler.animation_id = 0
      end
      # Damage
      if @battler.damage_pop
        damage(@battler.damage, @battler.critical)
        @battler.damage = nil
        @battler.critical = false
        @battler.damage_pop = false
      end
      # Collapse
      if @battler.damage == nil and @battler.dead?
        if @battler.is_a?(Game_Enemy)
          $game_system.se_play($data_system.enemy_collapse_se)
        else
          $game_system.se_play($data_system.actor_collapse_se)
        end
        collapse
        @battler_visible = false
      end
    end
    # Set sprite coordinates
    self.x = @battler.screen_x
    self.y = @battler.screen_y
    self.z = @battler.screen_z
  end
end

As you will notice there at some point, it's this Sprite class the one that handles the graphical portion of the damage or any other animation during battle. RPG::Sprite would only take care of the damage popup but only if that method is called from the Sprite_Battler class.

If you wanna understand the logic in use here, it's very simple indeed: keep the calculations separate from the drawing portion of the battle.
GOT IT (5 out of 6)

Let's trace back my steps:

In Game_Battler 1 i added the following:

Code:
  attr_accessor :a_damage
# add more when needed

Now I continue to Game_Enemy and added the following:

Code:
  #--------------------------------------------------------------------------
  # * Get Element Revision Value
  #     element_id : Element ID
  #--------------------------------------------------------------------------
  def element_rate(element_id)
    # Get a numerical value corresponding to element effectiveness
    table = [0,200,150,100,50,0,-100]
    result = table[$data_enemies[@enemy_id].element_ranks[element_id]]
    # If protected by state, this element is reduced by half
    for i in @states
      if $data_states[i].guard_element_set.include?(element_id)
        result /= 2
      end
    end
    # End Method
 
    # Store the damage value in the corresponding attribute
    case element_id
    when 1
      @a_damage = result
    # when 2
    #  @b_damage = result
    # etc
    end
 
    return result
  end

Now I head to Sprite_Battler and added the following:
Code:
      # Damage
      if @battler.damage_pop
        damage(@battler.damage, @battler.critical, @battler.a_damage) #add more if needed
        @battler.damage = nil
        @battler.critical = false
    
        @battler.a_damage = false
    
        @battler.damage_pop = false
      end

finally I modified the module RPG::Sprite

Code:
def damage(value, critical, element_a_damage) #add more when needed

#code

    if element_a_damage = @battler.a_damage
      bitmap.font.size = 20
      bitmap.font.color.set(0, 0, 0)
      bitmap.draw_text(-1, -1, 160, 20, "WEAK", 1)
      bitmap.draw_text(+1, -1, 160, 20, "WEAK", 1)
      bitmap.draw_text(-1, +1, 160, 20, "WEAK", 1)
      bitmap.draw_text(+1, +1, 160, 20, "WEAK", 1)
      bitmap.font.color.set(255, 255, 255)
      bitmap.draw_text(0, 0, 160, 20, "WEAK", 1)
    end

this now FINALLY reads, stores and outputs the information.

My final problem is Element Rate "E" or "Null" - this is where the Element has no Effect and outputs the Result as 0. Unfortunatelly no Text output is made. What else would I need to teak to make this work? I am also very very very sorry for my coding but I do my stuff 99% in-line 🙁

EDIT: I figured out annother Issue: If the Enemy is not "Weak" to the Element and I hit him with a skill that it still shows "WEAK" eventhough he is not weak to the element... Annoying

Full script here:


Code:
class RPG::Sprite
  def damage(value, critical, element_a_damage, element_e_damage, element_f_damage)
    dispose_damage
    if value.is_a?(Numeric)
      damage_string = value.abs.to_s
    else
      damage_string = value.to_s
    end
    bitmap = Bitmap.new(160, 48)
    bitmap.font.name = "Consolas"
    bitmap.font.size = 32
    bitmap.font.color.set(0, 0, 0)
    bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
    bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
    bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
    bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
    if value.is_a?(Numeric) and value < 0
      bitmap.font.color.set(176, 255, 144)
    else
      bitmap.font.color.set(255, 255, 255)
    end
    bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
    if critical
      bitmap.font.size = 20
      bitmap.font.color.set(0, 0, 0)
      bitmap.draw_text(-1, -1, 160, 20, "GET SMACKED", 1)
      bitmap.draw_text(+1, -1, 160, 20, "GET SMACKED", 1)
      bitmap.draw_text(-1, +1, 160, 20, "GET SMACKED", 1)
      bitmap.draw_text(+1, +1, 160, 20, "GET SMACKED", 1)
      bitmap.font.color.set(255, 255, 255)
      bitmap.draw_text(0, 0, 160, 20, "GET SMACKED", 1)
    end

    # table = [0,'Weak |','-','Neutral |','-','No Effect |','Absorb |']   
    
    if element_a_damage = @battler.a_damage
      bitmap.font.size = 20
      bitmap.font.color.set(255, 0, 0)
      bitmap.draw_text(0, 0, 160, 20, "W E A K", 1)
    end
    
    if element_e_damage = @battler.e_damage
      bitmap.font.size = 20
      bitmap.font.color.set(255, 255, 255)
      bitmap.draw_text(0, 0, 160, 20, "N O  E F F E C T", 1)
    end

    if element_f_damage = @battler.f_damage
      bitmap.font.size = 20
      bitmap.font.color.set(176, 255, 144)
      bitmap.draw_text(0, 0, 160, 20, "A B S O R B", 1)
    end
    
    @_damage_sprite = ::Sprite.new(self.viewport)
    @_damage_sprite.bitmap = bitmap
    @_damage_sprite.ox = 80
    @_damage_sprite.oy = 20
    @_damage_sprite.x = self.x
    @_damage_sprite.y = self.y - self.oy / 2 - 120
    @_damage_sprite.z = 3000
    @_damage_duration = 40
  end
end
At least I figured out the "No Effect" issue. (Wonky Code incoming)

Ruby:
if element_e_damage == @battler.e_damage && element_f_damage == @battler.f_damage && element_a_damage == @battler.a_damage && value == 0

So everytime the Output = 0 I get the "No Effect" Pop Up which is great because it also makes sense if basic damage without skill with 0 damage pops up the text.

Original thread: https://forums.rpgmakerweb.com/threads/elemental-efficiency-text-pop-up.168499/