Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Footstep sound effects

I'm looking for a script that will duplicate rm2k3's ability to play different sound effects while the hero walks on certain terrains. Just the hero, don't really want any npcs to make noises. The only scripts for this I've been able to find make sounds for npcs, or make only one type of sound effect regardless of terrain tags. Anyone have something like this?
Thanks in advance!
 
This is the RGSS/RGSS2 Support forum, meaning this forum is for people who are learning to script or people who need help using somebody else's script, this topic is more appropriate in Scripts Request. No big deal though, I've got something that should work just fine for you, but I haven't tested the edits so PM me if you have any problems (I don't watch these topics).

Code:
#===============================================================================
# ** Player & Event Step Sound Effects
#-------------------------------------------------------------------------------
# Written by    : Kain Nobel
# Version       : 1.0
# Last Updated  : 06.02.2008
#===============================================================================
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Character.StepSFX', 'Kain Nobel', 1.0, '06.02.2008')
#-------------------------------------------------------------------------------
# * SDK Enabled Test - BEGIN
#-------------------------------------------------------------------------------
if SDK.enabled?('Character.StepSFX')
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
# ~**                 CUSTOMIZABLE CONSTANTS - BEGIN                       **~ #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
module StepSFX
  #-----------------------------------------------------------------------------
  # * Horizontal Limit before event is out of range.
  #-----------------------------------------------------------------------------
  Arg_Dist_X  = 10
  #-----------------------------------------------------------------------------
  # * Vertical Limit before event is out of range.
  #-----------------------------------------------------------------------------
  Arg_Dist_Y  = 7
  #-----------------------------------------------------------------------------
  # * The master volume of the step sound effects.
  #-----------------------------------------------------------------------------
  Volume      = 50
  #-----------------------------------------------------------------------------
  # * The modifier for the step sound effect volume (for events vs player dist)
  #-----------------------------------------------------------------------------
  Adjust      = 2.5
  #-----------------------------------------------------------------------------
  # * Step sounds based on terrain tag ID
  #-----------------------------------------------------------------------------
  Tag = {
    # Default tag for no terrain
    0 => "Steps-00-Default",
    # Special Terrains such as grass, water, etc...
    1 => "Steps-01-Grass",
    2 => "Steps-02-Cement",
    3 => "Steps-03-Dirt",
    4 => "Steps-04-Water",
    5 => "Steps-05-Wood",
    6 => "Steps-06-Metal",
    7 => "Steps-07-Snow"
  }
end
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
# ~**                  CUSTOMIZABLE CONSTANTS - END                        **~ #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
#===============================================================================
# ** Game_Character
#-------------------------------------------------------------------------------
#   This class has been enhanced to use step sounds with player/events based on
# terrain tags.
#===============================================================================

#class Game_Character
class Game_Player < Game_Character
  #-----------------------------------------------------------------------------
  # * Alias Listing
  #-----------------------------------------------------------------------------
  alias_method  :kn_step_sounds_game_character_update,     :update
  #-----------------------------------------------------------------------------
  # * Update Method (Aliased)
  #-----------------------------------------------------------------------------
  def update
    if self.moving? && arg_frames
      if arg_screen_x && arg_screen_y
        if within_x && within_y
          play_step_sounds
        end
      end
    end
    kn_step_sounds_game_character_update
  end
  #-----------------------------------------------------------------------------
  # * Play Step Sounds
  #-----------------------------------------------------------------------------
  def play_step_sounds
    sound_effect = "Audio/SE/"+StepSFX::Tag[self.terrain_tag]
    if StepSFX::Tag.has_key?(self.terrain_tag)
      begin
        Audio.se_play(sound_effect, walk_volume, 75)
      rescue
      end
    end
  end
  #-----------------------------------------------------------------------------
  # * Frame Count Argument
  #-----------------------------------------------------------------------------
  def arg_frames
    unless @move_speed.nil?
      return ((Graphics.frame_count + 2 * self.id) % (18 - @move_speed)).zero?
    end
  end
  #-----------------------------------------------------------------------------
  # * Screen X Argument
  #-----------------------------------------------------------------------------
  def arg_screen_x
    return (self.screen_x > 0 && self.screen_x < 640)
  end
  #-----------------------------------------------------------------------------
  # * Screen Y Argument
  #-----------------------------------------------------------------------------
  def arg_screen_y
    return (self.screen_y > 0 && self.screen_y < 480)
  end
  #-----------------------------------------------------------------------------
  # * Distance X Argument
  #-----------------------------------------------------------------------------
  def arg_distance_x
    return ((self.x + $game_player.x) / 2)
  end
  #-----------------------------------------------------------------------------
  # * Distance Y Argument
  #-----------------------------------------------------------------------------
  def arg_distance_y
    return ((self.y + $game_player.y) / 2)
  end
  #-----------------------------------------------------------------------------
  # * Within Distance X
  #-----------------------------------------------------------------------------
  def within_x
    return arg_distance_x < (StepSFX::Arg_Dist_X * 32)
  end
  #-----------------------------------------------------------------------------
  # * Within Distance Y
  #-----------------------------------------------------------------------------
  def within_y
    return arg_distance_y < (StepSFX::Arg_Dist_Y * 32)
  end
  #-----------------------------------------------------------------------------
  # * Walk Volume
  #-----------------------------------------------------------------------------
  #def walk_volume
  #  return StepSFX::Volume+(StepSFX::Adjust*(arg_distance_x+arg_distance_y)/2)
  #end
end

#===============================================================================
# ** Game_Player
#-------------------------------------------------------------------------------
#   Game_Player's walk volume doesn't have to be measured against anything, so
# this class's volume is constantly a certain value * 2. This overrides the
# 'walk_volume' method in Game_Character.
#===============================================================================

class Game_Player < Game_Character
  #-----------------------------------------------------------------------------
  # * Define Walk Volume
  #-----------------------------------------------------------------------------
  def walk_volume
    return StepSFX::Volume * 2
  end
end

#-------------------------------------------------------------------------------
# * SDK Enabled Test - END
#-------------------------------------------------------------------------------
end

This is an edited version of my Character.StepSFX scripts, its meant to be for all events/player, but I've edited to be player-only. Yes, it does have terrain-based step sounds, and I haven't tested the edits but I placed a # in front of the origional code (if you want to change it back to player and events). Are you going to be needing audiofiles for this? Here I'll provide you with the ones I've found.

http://www.mediafire.com/?sharekey=a721 ... 11e7e015c0

With this version, theres 3 constants that probably won't be of any use to you (because they're for events), and thats Arg_X, Arg_Y and Adjust (constants that modify the output of event sounds). I purposely left them in there incase you decide you want to use it for events later, you'll easily be able to change it back.

Also, if you don't use the SDK, delete the SDK.log() and SDK.enabled?() test and don't forget the very last 'end' at the bottom of the script and you should be ready to roll.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top