Little help with Hurt Sounds script by MrTrivel

Link

I want to add some small changes to this script so that if an actor has multiple tags, it will choose one of the sounds at random.
The script is beyond "just patch it and it works", it might as well as rewrite it.
Now, I wrote my own version. And I haven't tested it yet though.
Code:
#================================================
# > Use tag <hurt: SE_name, volume, pitch>
#   Example: <hurt: Damage1, 100, 100>
#================================================
class RPG::BaseItem
 
  def hurt_sounds
    return @hsounds if @hsounds
    @hsounds = []
    note.split(/[\r\n]+/).each do |line|
      if line =~ /<hurt\s*:\s*(\w+),\s*(\d+),\s*(\d+)>/i
        @hsounds << RPG::SE.new($1.to_s, $2.to_i, $3.to_i)
      end
    end
    return @hsounds
  end
 
end

class Game_Battler
  def data_battler
    actor? ? actor : enemy
  end
 
  alias theo_hurt_sound_exe_damage execute_damage
  def execute_damage(user)
    theo_hurt_sound_exe_damage(user)
    sounds = data_battler.hurt_sounds
    return if sounds.empty? || @result.hp_damage <= 0
    sounds.sample.play
  end
 
end
I tried it and only the sound specified in the first tag played.
Moved to: RGSSx Script Support
Modified and tested
Code:
#================================================
# > Use tag <hurt: SE_name, volume, pitch>
#   Example: <hurt: Damage1, 100, 100>
#================================================
class RPG::BaseItem
 
  def hurt_sounds
    return @hsounds if @hsounds
    @hsounds = []
    note.split(/[\r\n]+/).each do |line|
      if line =~ /<hurt\s*:\s*(\w+),\s*(\d+),\s*(\d+)>/i
        @hsounds << RPG::SE.new($1.to_s, $2.to_i, $3.to_i)
      end
    end
    return @hsounds
  end
 
end

class Game_Battler
  def data_battler
    actor? ? actor : enemy
  end
 
  alias theo_hurt_sound_exe_damage execute_damage
  def execute_damage(user)
    theo_hurt_sound_exe_damage(user)
    sounds = data_battler.hurt_sounds
    return if sounds.empty? || @result.hp_damage <= 0
    cnt = sounds.size
    plsnd = rand(cnt)
    audsnd = sounds[plsnd]
    audsnd.play
  end
 
end
It works, thank you both for help!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/little-help-with-hurt-sounds-script-by-mrtrivel.108913/