#===============================================================================
# Terrain Step Sound + Events
# Version 1.3
# Author game_guy
# New Features by Zexion
#-------------------------------------------------------------------------------
# Intro:
# Create nice aesthetics with terrain noise. As you walk across grass or sand,
# let it play a beautiful noise to add to the atmosphere and realism of the
# game.
#
# Features:
# Specific Sound for Each Terrain
# Specific Sounds for Each Tileset
# Specify Volume and Pitch
# Specify an array of sounds for each terrain, allowing random sounds for each step
# Specify events that can play these sounds.
#
# Instructions:
# Setup the config below, its pretty self explanatory, more instructions
# with config.
#
# You can now change the sound rate in game using a script call.
# $game_map.rate = X
# X = sound rate (the lower the value, the more frequent the sounds)
#
# Add the Name_Tag ("steps" by default) to the event page name (without quotes)
# to add dynamic footstep sounds to that event.
#
# Credits:
# game_guy ~ For creating it
# Tuggernuts ~ For requesting it a long time ago
# Sase ~ For also requeseting it
# Zex - For the Event & move_speed edit
# kk20 - for listening to zex's complaints
#===============================================================================
module TSS
# Adjust this to your liking
Wait = 20
Name_Tag = "steps"
# Ignore this
Terrains, Tilesets = [], []
#===========================================================================
# Enter in sounds for each terrain tag
# Goes from 0-8. Set as nil to disable that terrain or delete the line.
# Each terrain must now be an array. This allows you to define multiple
# sound effects for each terrain.
#===========================================================================
Terrains[0] = []
Terrains[1] = [["FS - 03 - Wood", 40, 0],["FS - 04 - Wood", 40, 0]]
Terrains[2] = ['FS - 05 - Metal']
Terrains[3] = ['FS - 07 - Hollow Metal']
Terrains[4] = [["FS - 09 - Concrete", 40, 0]]
Terrains[5] = [["FS - 11 - Dirt", 40, 0],["FS - 11 - Dirt", 40, 0]]
Terrains[6] = [["FS - 13 - Grass", 40, 0], ["FS - 14 - Grass", 40, 0]]
#===========================================================================
# If you would like to specifiy a volume and pitch, simply set the
# terrain as an array.
# Terrains[7] = [["sound", volume, pitch]]
# Just set it as a string if you would like the volume to be at 100 and
# pitch at 0.
# This also applies for tilesets below.
# You can also define multiple sound effects with pitch and volume.
#===========================================================================
Terrains[7] = [["FS - 01 - Water", 50, 0],["FS - 02 - Water", 50, 0]]
#===========================================================================
# With tilesets, you can set specific sounds for each tileset so you don't
# have the same sounds. Add a new line and put
# Tilesets[tileset id] = []
# Then for each terrain put
# Tilesets[tileset id][terrain id] = ["sound file", "sound file2", etc...]
# If a sound doesn't exist for a tileset, it will play a default sound,
# if a default doesn't exist, no sound at all.
#===========================================================================
end
#-------------------------------------------------------------------------------
# Game_Map
#-------------------------------------------------------------------------------
class Game_Map
attr_accessor :map # make public
end
#-------------------------------------------------------------------------------
# Game_Character
#-------------------------------------------------------------------------------
# Adds Gameus's terrain_sound method to game_character.
#-------------------------------------------------------------------------------
class Game_Character
attr_accessor :move_speed # make public
#-----------------------------------------------------------------------------
# Initialize ss_index
#-----------------------------------------------------------------------------
alias g_c_sfe_init initialize
def initialize
g_c_sfe_init
@ss_index = 0
@timer = 0
@tss_speed = @move_speed
set_tss_offset
end
#-----------------------------------------------------------------------------
# Updates the timer when needed
#-----------------------------------------------------------------------------
alias g_c_sfe_update update
def update
g_c_sfe_update
@timer -= 1 if @timer > 0
if @tss_speed != self.move_speed
set_tss_offset
end
end
#-----------------------------------------------------------------------------
# Sets the sound offset
#-----------------------------------------------------------------------------
def set_tss_offset
# Timer offset by movespeed
case self.move_speed
when 0..2
@tss_offset = TSS::Wait + self.move_speed
when 3
@tss_offset = TSS::Wait
else
@tss_offset = TSS::Wait - self.move_speed * 2
end
end
#-----------------------------------------------------------------------------
# Returns the array to be used later
#-----------------------------------------------------------------------------
def terrain_sound
if TSS::Tilesets[$game_map.map.tileset_id] != nil
sounds = TSS::Tilesets[$game_map.map.tileset_id][self.terrain_tag]
else
sounds = TSS::Terrains[self.terrain_tag]
end
return nil if sounds == nil || !sounds.is_a?(Array) || sounds.size < 1
index_max = sounds.size - 1
@ss_index = (@ss_index < index_max) ? (@ss_index + 1) : 0
sound = sounds[@ss_index]
if sound.is_a?(Array)
return [sound[0], sound[1], sound[2]]
else
return [sound, 100, 0]
end
end
end
#-------------------------------------------------------------------------------
# Game_Player
#-------------------------------------------------------------------------------
Tss_Parent = $BlizzABS ? (Map_Actor) : (Game_Character)
class Game_Player < Tss_Parent
#-----------------------------------------------------------------------------
# Adds step sounds to the player
#-----------------------------------------------------------------------------
def update_move
# Make sure this is the player
if self != $game_event && @timer == 0
# Play the sound effect
terrain = self.terrain_sound
if terrain != nil
vol = terrain[1]
pit = terrain[2]
son = terrain[0]
Audio.se_play('Audio/SE/' + son, vol, pit)
end
# Set timer
@timer = @tss_offset
end
# Call original code
super
end
end
#-------------------------------------------------------------------------------
# Game_Event
#-------------------------------------------------------------------------------
class Game_Event < Game_Character
#-----------------------------------------------------------------------------
# Set the variable for checking if the event should make a sound
#-----------------------------------------------------------------------------
alias g_e_sfe_init initialize
def initialize(map_id, event)
g_e_sfe_init(map_id, event)
@tss = self.name.include?(TSS::Name_Tag) ? true : false
end
#--------------------------------------------------------------------------
# * Returns the event's name
#--------------------------------------------------------------------------
def name
return @event.name
end
#-----------------------------------------------------------------------------
# Returns the distance of this event from the player
#-----------------------------------------------------------------------------
def range?
if $BlizzABS && BlizzABS::Config::PIXEL_MOVEMENT_RATE == 1
player_x = $game_player.x / 2 # Adjusted for 1.0 pixel movement rate
player_y = $game_player.y / 2 # Adjusted for 1.0 pixel movement rate
else
player_x = $game_player.x
player_y = $game_player.y
end
radius = (Math.hypot((self.x - player_x), (self.y - player_y))).abs.floor
return (radius)
end
#-----------------------------------------------------------------------------
# Adds step sounds to the event with dynamic volume
#-----------------------------------------------------------------------------
def update_move
# Check if the event should play a sound
if @tss
# Make sure it's an event
if self != $game_player
# Check if the event is anywhere near the player
if range? <= 6 && @timer == 0
# The amount to subtract from the normal volume
sub_vol = 4 * range?
# Play the sound effect
terrain = self.terrain_sound
if terrain != nil
vol = terrain[1]
pit = terrain[2]
son = terrain[0]
# Dynamic sound edit
vol = vol - sub_vol
vol = 0 if vol < 0
Audio.se_play('Audio/SE/' + son, vol, pit)
end
# Set timer
@timer = @tss_offset
end
end
end
# Call original code
super
end
end