MV Battler flash when hit with weakness for MV? [SOLVED]

This is another one I've looked around for a while yet found no good answer for. When I tried to google if someone had possibly made this plugin beforehand, the results led back to MY OWN THREAD.

The basic idea is that I think RPG Maker has no sauce (translation: does not feel good) without specific sound effects for resisted/immune/super effective hits. Enemies flashing a certain color when you hit them with a weakness is also important.

Moghunter has an "enemies shake when you hit them" function, but aside from that nothing else. Yanfly's Hit Damage Sounds is only for armors and enemies, when I want the sound to be made per elemental hit regardless of armor.

I had a scriptlet made in VX Ace that allows me to do just that, but no such equivalent in MV.

Spoiler: Shake Weakness VX Ace Code
Ruby:
class Game_ActionResult
  attr_accessor :weakness_hit
  attr_accessor :resist_hit
  attr_accessor :immune_hit
  attr_accessor :normal_hit
 
  alias tlb_gar_clear_hit_flags clear_hit_flags
  def clear_hit_flags
    tlb_gar_clear_hit_flags
    @weakness_hit = false
    @resist_hit = false
    @immune_hit = false
    @normal_hit = false
  end
end

class Game_Battler < Game_BattlerBase
  def item_apply(user, item)
    @result.clear
    @result.used = item_test(user, item)
    @result.missed = (@result.used && rand >= item_hit(user, item))
    @result.evaded = ([email protected] && rand < item_eva(user, item))
    if @result.hit?
      unless item.damage.none?
        @result.critical = (rand < item_cri(user, item))
        @result.weakness_hit = item_element_rate(user, item) > 1
        @result.resist_hit = item_element_rate(user, item) < 1 unless item_element_rate(user, item) == 0
        @result.immune_hit = item_element_rate(user, item) == 0
        @result.normal_hit = item_element_rate(user, item) == 1
        make_damage_value(user, item)
        execute_damage(user)
      end
      item.effects.each {|effect| item_effect_apply(user, item, effect) }
      item_user_effect(user, item)
    end
  end
end

class Game_Enemy < Game_Battler
  def perform_weakness_effect
    @sprite_effect_type = :weak
    RPG::SE.new("sh-sfx-weaksfx", 100, 90).play
  end
 
  def perform_resistance_effect
    @sprite_effect_type = :resist
    RPG::SE.new("Blow2", 100, 60).play
  end
 
  def perform_immune_effect
    @sprite_effect_type = :immune
    RPG::SE.new("Sword1", 100, 150).play
  end

  def perform_shielded_effect
    @sprite_effect_type = :shielded
    RPG::SE.new("MD-SFX-tool_hammer_02", 100, 100).play
  end
 
    def perform_mpdamage_effect
    @sprite_effect_type = :mpdamage
    RPG::SE.new("Ice2", 95, 150).play
  end
 
  def perform_normal_effect
    @sprite_effect_type = :normal
  end
end

class Game_Actor < Game_Battler
  def perform_weakness_effect
    @sprite_effect_type = :weak
    RPG::SE.new("sh-sfx-weaksfx", 100, 90).play
  end
 
  def perform_resistance_effect
    @sprite_effect_type = :resist
    RPG::SE.new("Blow2", 100, 70).play
  end
 
  def perform_immune_effect
    @sprite_effect_type = :immune
    RPG::SE.new("Sword1", 100, 150).play
  end
 
  def perform_shielded_effect
    @sprite_effect_type = :shielded
    RPG::SE.new("Hammer", 80, 150).play
  end
 
  def perform_mpdamage_effect
    @sprite_effect_type = :mpdamage
    RPG::SE.new("Ice2", 95, 150).play
  end
 
  def perform_normal_effect
    @sprite_effect_type = :normal
    Sound.play_actor_damage
  end
 
end

class Sprite_Battler < Sprite_Base
  def start_effect(effect_type)
    @effect_type = effect_type
    case @effect_type
    when :appear
      @effect_duration = 16
      @battler_visible = true
    when :disappear
      @effect_duration = 32
      @battler_visible = false
    when :whiten
      @effect_duration = 16
      @battler_visible = true
    when :blink
      @effect_duration = 20
      @battler_visible = true
    when :weak
      @effect_duration = 30
      @battler_visible = true
    when :resist
      @effect_duration = 30
      @battler_visible = true
    when :immune
      @effect_duration = 30
      @battler_visible = true
    when :shielded
      @effect_duration = 30
      @battler_visible = true
    when :mpdamage
      @effect_duration = 30
      @battler_visible = true
    when :normal
      @effect_duration = 30
      @battler_visible = true
    when :collapse
      @effect_duration = 1
      @battler_visible = false
    when :boss_collapse
      @effect_duration = bitmap.height
      @battler_visible = false
    when :instant_collapse
      @effect_duration = 1
      @battler_visible = false
    end
    revert_to_normal
  end
 
  alias sprite_battler_update_effect_trihan update_effect
  def update_effect
    sprite_battler_update_effect_trihan
    case @effect_type
    when :weak
      update_weak
    when :resist
      update_resist
    when :immune
      update_immune
    when :shielded
      update_shielded
    when :mpdamage
      update_mpdamage
    when :normal
      update_normal
    end
  end
 
  def update_weak
    return if bitmap.nil?
    self.color.set(255, 0, 0, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 6 - 2
  end
 
  def update_resist
    return if bitmap.nil?
    self.color.set(0, 0, 255, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 2 - 2
  end
 
  def update_mpdamage
    return if bitmap.nil?
    self.color.set(220, 0, 220, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 2 - 2
  end
 
  def update_immune
    return if bitmap.nil?
    self.color.set(50, 50, 50, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 1 - 2
  end
 
  def update_shielded
    return if bitmap.nil?
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 1 - 2
  end
 
  def update_normal
    return if bitmap.nil?
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 3 - 2
  end
 
end

# Berry’s shield is 91
# Chroma’s Shields are 92, 93, 94, 95
# Infinite Barrier is 103

class Window_BattleLog < Window_Selectable
  def display_hp_damage(target, item)
    return if target.result.hp_damage == 0 && item && !item.damage.to_hp?
    if target.result.weakness_hit
      target.perform_shielded_effect if target.state?(16) || target.state?(23) || target.state?(67) || target.state?(91) || target.state?(92) || target.state?(93) || target.state?(94) || target.state?(95) || target.state?(103)
      target.perform_weakness_effect unless target.result.hp_damage < 0
      $game_troop.screen.start_shake(5, 5, 10)
    elsif target.result.resist_hit
      target.perform_shielded_effect if target.state?(16) || target.state?(23) || target.state?(67) || target.state?(91) || target.state?(92) || target.state?(93) || target.state?(94) || target.state?(95) || target.state?(103)
      target.perform_resistance_effect
    elsif target.result.immune_hit && target.result.hp_damage = 0
#    if target.state?(16) || target.state?(23) || target.state?(67) || target.state?(91) || target.state?(92) || target.state?(93) || target.state?(94) || target.state?(95) || target.state?(103)
#      target.perform_shielded_effect
#      else
      target.perform_immune_effect
#    end
    elsif target.result.hp_damage == 0
      if target.state?(16) || target.state?(23) || target.state?(67) || target.state?(91) || target.state?(92) || target.state?(93) || target.state?(94) || target.state?(95) || target.state?(103)
      target.perform_shielded_effect
      else
      target.perform_immune_effect
    end
    elsif target.result.hp_damage > 0 && target.result.hp_drain == 0
      target.perform_normal_effect
      target.perform_shielded_effect if target.state?(16) || target.state?(23) || target.state?(67) || target.state?(91) || target.state?(92) || target.state?(93) || target.state?(94) || target.state?(95) || target.state?(103)
      target.perform_damage_effect
    elsif target.result.hp_damage < 0 && target.result.hp_drain > 0
      target.perform_normal_effect
    end
  else
    Sound.play_recovery if target.result.hp_damage < 0
  end

#=begin target.perform_mpdamage_effect
  def display_mp_damage(target, item)
    return if target.result.mp_damage == 0 && item && !item.damage.to_mp?
    if target.result.weakness_hit
      target.perform_mpdamage_effect
      target.perform_weakness_effect unless target.result.mp_damage < 0
      $game_troop.screen.start_shake(5, 5, 10)
    elsif target.result.immune_hit && target.result.mp_damage = 0
#    if target.state?(16) || target.state?(23) || target.state?(67) || target.state?(91) || target.state?(92) || target.state?(93) || target.state?(94) || target.state?(95) || target.state?(103)
#      target.perform_shielded_effect
#      else
      target.perform_immune_effect
#    end
    elsif target.result.mp_damage == 0
#      if target.state?(16) || target.state?(23) || target.state?(67) || target.state?(91) || target.state?(92) || target.state?(93) || target.state?(94) || target.state?(95) || target.state?(103)
      target.perform_mpdamage_effect
#      else
#      target.perform_immune_effect
#    end
    elsif target.result.mp_damage > 0 && target.result.mp_drain == 0
      target.perform_mpdamage_effect
#      target.perform_shielded_effect if target.state?(16) || target.state?(23) || target.state?(67) || target.state?(91) || target.state?(92) || target.state?(93) || target.state?(94) || target.state?(95) || target.state?(103)
    elsif target.result.mp_damage < 0 && target.result.mp_drain > 0
      target.perform_mpdamage_effect
    end
  else
    Sound.play_recovery if target.result.mp_damage < 0
  end
#=end
end

I was wondering if it could be possible if someone could convert this code into Javascript, since it's my only frame of reference for this idea.
You could do some stuff easily with action sequences.

Do an if check for the target's element rate, then use the enemy effect command from pack 2, or the flash screen command (also pack 2, allows for customized colors). You can also do a custom "critical hit for this specific element" with the SE command in pack 1.

If you don't want to copy and paste action sequence commands, you could pull out the JavaScript equivalents and add them as steps to the Damage Core plugin, but that might be more complicated.
I was writing this whole elaborate reply and then my guy comes in with that.
You could do some stuff easily with action sequences.

Do an if check for the target's element rate, then use the enemy effect command from pack 2, or the flash screen command (also pack 2, allows for customized colors). You can also do a custom "critical hit for this specific element" with the SE command in pack 1.

If you don't want to copy and paste action sequence commands, you could pull out the JavaScript equivalents and add them as steps to the Damage Core plugin, but that might be more complicated.

Got something cooking with the Damage Core suggestion, but I don't know if there's any script calls to make battlers "flash" unless I tie a battle animation ID to them... but even that got me stumped too.

For example, I tried to use "battler.startAnimation(294, false, 0);" but it didn't do anything.

Also, is it "target.elementRate(elementId)" to check the enemy's elemental rates?

With this step I tried to use "if (target.elementRate(elementID) > 1;", but all it did was make all attacks act as if they hit with neutral damage.
I underestimated my own resourcefulness, apparently.

I got it to work, but in a different way than I originally expected. The key was to use Victor's Damage Pop-Ups as the basis, since it uses the same kind of element rate tracking that I used back in VX Ace.

All I have to do is attach

Code:
 target.startAnimation([flashing animation], false, 0);
AudioManager.playSe({name: "[appropriate sfx]", pan: 0, pitch: 100, volume: 100})

To the parts of Victor's code that control what kind of pop-up is displayed when elemental damage is done, and that solves my problem.

Original thread: https://forums.rpgmakerweb.com/threads/battler-flash-when-hit-with-weakness-for-mv-solved.154660/