module Play_battle_sound
=begin
Author: GGZiron
Terms of use: Free for comercial and uncomercial projects. You have to credit
me as GGZiron
Version 1.0.1
Date of release 30.05.2018
About the script: It allows the actors to produce sound when hit or being hit
during battle.
=end
# Key values must represent the actor's id, and the string
# is the filename (without the extension) of sound he/she ll produce
# Do not try to use sound files that rpg maker cannot play.
# The sound file is from the SE directory or SE built in RTP resourses.
ACTOR_ATTACKS ={
1 => "Blow2", #in this example, actor with ID 1 will use
#sound named "Blow2" from the directory when attack.
#add more entries
}
ACTOR_IS_HIT ={
1 => "Blow2", #in this example, actor with ID 1 will try to use
#sound named "Blow2" from the directory when hit.
#add more entries
}
# WARNING: Do not add actor with invalid sound name. That will give error!!!
# Don't include actors you don't want to have sounds.
#Set what volume and pitch will have the actor's sound
SOUND_VOLUME = 100
SOUND_PITCH = 100
end
class Game_Battler < Game_BattlerBase
#===========================Edited Methods===================================
alias_method :execute_damage_old, :execute_damage
def execute_damage(user)
execute_damage_old(user)
set_battle_sound(user, true) if @result.hp_damage > 0 && self.actor?
end
alias_method :item_apply_old, :item_apply
def item_apply(user, item)
set_battle_sound(user, false) if user.actor?
item_apply_old(user, item)
end
#============================================================================
#===========================New Method=======================================
def set_battle_sound(user, attacked)
if self.actor? && user.actor?
return if self.id == user.id
end
sound = attacked ? Play_battle_sound::ACTOR_IS_HIT[self.id] : Play_battle_sound::ACTOR_ATTACKS[user.id]
volume = Play_battle_sound::SOUND_VOLUME
pitch = Play_battle_sound::SOUND_PITCH
Audio.se_play("Audio/SE/" + sound, volume, pitch) if sound
end
#============================================================================
end