Alexeyus пишет:
Помогите, пожалуйста найти скрипт звука.
По приближении или удалении к определенному ивенту, этот скрипт должен
увеличивать/уменьшать громкость BGS, BGM, Se или же Me.
Зарание благодарен.
#==============================================================================
# Enhance Audio
#==============================================================================
# Original Title : Dynamic Sound Emitting Areas/Events
# Original Author : modern algebra
# Original Version : 2.0
#==============================================================================
# Modified by : OriginalWij
# Mod Version : 1.1
#==============================================================================
#==============================================================================
# Event Config (Area Config is below)
#==============================================================================
# Use an event comment with these codes:
#
# \sound[parameter = value]
#
# Parameters for each sound:
# ---------------------------------------------------------------------------
# bgm_name/bgs_name/se_name/me_name = filename [Default = '']
# bgm_volume/bgs_volume/se_volume/me_volume = volume [Default = 100]
# bgm_pitch/bgs_pitch/se_pitch/me_pitch = pitch [Default = 100]
# bgm_range/bgs_range/se_range/me_range = radius (tiles) [Default = 10]
# se_delay/me_delay = delay before repeating (in frames) [Default = 20]
# se_random/me_random = variance (±) of se_delay/me_delay [Default = 0]
#
# EXAMPLE:
# \sound[se_name = 'Chicken']
# \sound[se_volume = 80]
# \sound[se_delay = 440]
# \sound[se_random = 60]
# (plays SE: 'Chicken' at volume = 80 with range = 10 tiles)
# (and repeat every 380 - 500 frames)
#==============================================================================
#==============================================================================
# RPG::Area
#==============================================================================
class RPG::Area
#--------------------------------------------------------------------------
# Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :sound_emission
#--------------------------------------------------------------------------
# Setup Sound Emissions
#--------------------------------------------------------------------------
def setup_sound_emissions
s = @sound_emission = RPG::Sound_Emission.new
case @id
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Area Config
#------------------------------------------------------------------------
# EXAMPLE:
# when 1 (← area ID)
# s.bgs_name = 'River'
# s.bgs_range = 15
# s.bgs_volume = 110
# (Area 1 plays: BGS 'River' at volume = 110 with range = 15 tiles)
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
when 1 # Area 1
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# End Area Config
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
end
@sound_emission.rect = self.rect
@sound_emission.initialize_frame_counts
end
end
#==============================================================================
# RPG::Sound_Emission
#==============================================================================
class RPG::Sound_Emission
#--------------------------------------------------------------------------
# Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :rect
attr_accessor :bgs_name
attr_accessor :bgs_pitch
attr_accessor :bgs_range
attr_accessor :bgs_volume
attr_accessor :bgm_name
attr_accessor :bgm_pitch
attr_accessor :bgm_range
attr_accessor :bgm_volume
attr_accessor :se_name
attr_accessor :se_pitch
attr_accessor :se_range
attr_accessor :se_volume
attr_accessor :se_delay
attr_accessor :se_random
attr_accessor :me_name
attr_accessor :me_pitch
attr_accessor :me_range
attr_accessor :me_volume
attr_accessor :me_delay
attr_accessor :me_random
#--------------------------------------------------------------------------
# Setup Sound Emissions
#--------------------------------------------------------------------------
def initialize
@rect = Rect.new (0, 0, 0, 0)
@bgs_name = @bgm_name = @se_name = @me_name = ''
@bgs_volume = @bgm_volume = @se_volume = @me_volume = 100
@bgs_pitch = @bgm_pitch = @se_pitch = @me_pitch = 100
@bgs_range = @bgm_range = @se_range = @me_range = 10
@se_delay = @me_delay = 20
@se_random = @me_random = 0
initialize_frame_counts
end
#--------------------------------------------------------------------------
# Initialize Frame Counts
#--------------------------------------------------------------------------
def initialize_frame_counts
@se_frame_count = @se_delay + rand (2 * @se_random).floor - @se_random
@me_frame_count = @me_delay + rand (2 * @me_random).floor - @me_random
end
#--------------------------------------------------------------------------
# Update Sound
#--------------------------------------------------------------------------
def update
@stopped = false
bgm.play if @bgm_name != ''
bgs.play if @bgs_name != ''
update_se if @se_name != ''
update_me if @me_name != ''
end
#--------------------------------------------------------------------------
# Stop Sound
#--------------------------------------------------------------------------
def stop
return if @stopped
RPG::BGM.stop if @bgm_name != ''
RPG::BGS.stop if @bgs_name != ''
@stopped = true
end
#--------------------------------------------------------------------------
# Get BGM
#--------------------------------------------------------------------------
def bgm
@bgm = RPG::BGM.new (@bgm_name, 0, @bgm_pitch) if @bgm == nil
@bgm.volume = volume (@bgm_range, @bgm_volume)
return @bgm
end
#--------------------------------------------------------------------------
# Get BGS
#--------------------------------------------------------------------------
def bgs
@bgs = RPG::BGS.new (@bgs_name, 0, @bgs_pitch) if @bgs == nil
@bgs.volume = volume (@bgs_range, @bgs_volume)
return @bgs
end
#--------------------------------------------------------------------------
# Get SE
#--------------------------------------------------------------------------
def se
@se = RPG::SE.new (@se_name, 0, @se_pitch) if @se == nil
@se.volume = volume (@se_range, @se_volume)
return @se
end
#--------------------------------------------------------------------------
# Update SE
#--------------------------------------------------------------------------
def update_se
if @se_frame_count == 0
se.play
@se_frame_count = @se_delay + rand (2 * @se_random).floor - @se_random
else
@se_frame_count -= 1
end
end
#--------------------------------------------------------------------------
# Get ME
#--------------------------------------------------------------------------
def me
@me = RPG::ME.new (@me_name, 0, @me_pitch) if @me == nil
@me.volume = volume (@me_range, @me_volume)
return @me
end
#--------------------------------------------------------------------------
# Update ME
#--------------------------------------------------------------------------
def update_me
if @me_frame_count == 0
me.play
@me_frame_count = @me_delay + rand (2 * @me_random).floor - @me_random
else
@me_frame_count -= 1
end
end
#--------------------------------------------------------------------------
# Volume
#--------------------------------------------------------------------------
def volume (radius, max_volume)
x, y = $game_player.x, $game_player.y
xd, yd = x - @rect.x, y - @rect.y
rx, ry, rw, rh = @rect.x, @rect.y, @rect.width, @rect.height
xd > 0 ? xd = x.between?(rx, rx + rw) ? 0 : xd - rw : xd *= -1
yd > 0 ? yd = y.between?(ry, ry + rh) ? 0 : yd - rh : yd *= -1
total_distance = Math.sqrt(xd * xd + yd * yd).ceil.to_i
percent = (total_distance.to_f / radius.to_f) * 100
percent = (100 - [percent, 100].min).to_f / 100.0
return (percent * max_volume.to_f).to_i
end
end
#==============================================================================
# Game_Event
#==============================================================================
class Game_Event
#--------------------------------------------------------------------------
# Setup
#--------------------------------------------------------------------------
alias ma_sound_emit_obj_stp_event_pg_85nd setup unless $@
def setup (new_page)
ma_sound_emit_obj_stp_event_pg_85nd (new_page)
@sound_emission.stop unless @sound_emission.nil?
unless @page == nil
s = @sound_emission = RPG::Sound_Emission.new
@sound_emission.rect = Rect.new (@x, @y, 1, 1)
comments = []
@page.list.each {|i|
i.code == 108 || i.code == 408 ? comments.push(i) : break
}
comments.each {|i|
text = i.parameters[0].dup
while text.sub! (/\\SOUND\[(.+)\]/i) { '' } != nil
eval ("@sound_emission." + $1.to_s)
end
}
end
end
#--------------------------------------------------------------------------
# Update
#--------------------------------------------------------------------------
alias modalg_snd_emssn_script_upd_evnt_4n2 update unless $@
def update
modalg_snd_emssn_script_upd_evnt_4n2
return if @sound_emission.nil?
@sound_emission.rect.x, @sound_emission.rect.y = @x, @y
@sound_emission.update
end
end
#==============================================================================
# Game_Map
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# Setup
#--------------------------------------------------------------------------
alias modalg_dynamic_snd_emit_stup_rn4 setup unless $@
def setup(map_id)
@areas.each { |area| area.sound_emission.stop } unless @areas.nil?
modalg_dynamic_snd_emit_stup_rn4 (map_id)
@areas = []
$data_areas.values.each{|area| @areas.push(area) if map_id == area.map_id}
@areas.each{|i| i.setup_sound_emissions if i.sound_emission == nil}
@advanced_areas = false
begin
$data_areas[1].active?
@advanced_areas = true
rescue
end
end
#--------------------------------------------------------------------------
# Update
#--------------------------------------------------------------------------
alias modalg_dyn_sound_emitting_objects_upd_4h3 update unless $@
def update
modalg_dyn_sound_emitting_objects_upd_4h3
@areas.each {|area|
if @advanced_areas && !area.active?
area.sound_emission.stop
else
area.sound_emission.update
end
}
end
end