[XP] Terrain Step Sound

Started by G_G, April 26, 2011, 08:42:09 pm

Previous topic - Next topic

G_G

April 26, 2011, 08:42:09 pm Last Edit: September 08, 2019, 04:26:16 pm by KK20
Terrain Step Sound
Authors: game_guy
Version: 1.3
Type: Environment Add-on
Key Term: Environment Add-on

Introduction

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 to allow multiple sounds per terrain

Screenshots

N/A
Screenshots can't produce sound.

Demo

N/A
Links can't produce sound either.

Script

v1.2: ShowHide

#===============================================================================
# Terrain Step Sound
# Version 1.2
# Author game_guy
#-------------------------------------------------------------------------------
# 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
#
# 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)
#
# Credits:
# game_guy ~ For creating it
# Tuggernuts ~ For requesting it a long time ago
# Sase ~ For also requeseting it
#===============================================================================
module TSS
  # In Frames Recommended 5-10
  Wait = 10
  # Ignore the next 2 lines
  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] = ['001-System01', '002-System02', '003-System03']
  Terrains[1] = ['fs_wood_hard1']
  Terrains[2] = ['fs_grass03']
  Terrains[3] = ['fs_stone_hoof2']
  Terrains[4] = ['as_na_grassmove2']
  Terrains[5] = ['fs_water_hard1']
  Terrains[6] = ['fs_dirt_hard1']
  #===========================================================================
  # 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] = [["sound", 80, 10], "sound2", ["sound3", 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.
  #===========================================================================
  Tilesets[2] = []
  Tilesets[2][0] = ["Sound"]
  Tilesets[2][1] = [["sound", 75, 50]]
end
class Game_Map
 
  attr_accessor :rate
 
  alias gg_init_terrain_sounds_map_lat initialize
  def initialize
    @rate = TSS::Wait
    return gg_init_terrain_sounds_map_lat
  end
 
  def terrain_sound
    if TSS::Tilesets[@map.tileset_id] != nil
      sounds = TSS::Tilesets[@map.tileset_id][$game_player.terrain_tag]
    else
      sounds = TSS::Terrains[$game_player.terrain_tag]
    end
    return nil if sounds == nil || !sounds.is_a?(Array) || sounds.size < 1
    sound = sounds[rand(sounds.size)]
    if sound.is_a?(Array)
      return [sound[0], sound[1], sound[2]]
    else
      return [sound, 100, 0]
    end
  end
 
end

class Game_Player < Game_Character
 
  def update_move
    @timer = $game_map.rate if @timer == nil
    @timer -= 1
    if @timer < 1
      terrain = $game_map.terrain_sound
      if terrain != nil
        vol = terrain[1]
        pit = terrain[2]
        son = terrain[0]
        Audio.se_play('Audio/SE/' + son, vol, pit)
      end
      @timer = $game_map.rate
    end
    super
  end
 
end


Zexion added a few more features: https://forum.chaos-project.com/index.php/topic,9460.msg192088.html#msg192088
v1.3: ShowHide

#===============================================================================
# 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


Instructions

In script.

Compatibility

Not tested with SDK.

Credits and Thanks

  • game_guy ~ For creating it
  • Tuggernuts ~ For requesting it a long time ago
  • Sase ~ For also requeseting it

Author's Notes

Enjoy!

Cid

Is there a way to specify the volume and pitch of each sound effect?

G_G

*Updates*

Now at 1.1, you can now specify volume and pitch for each terrain.

Cid

Hmm, I get this error (upon moving the character) whenever I make use of the volume/pitch adjuster:

QuoteScript 'Terrain Sound' line 90: TypeError occured.
cannot convert nil into String


Have I missed something during set-up?

G_G

Fixed. Simple typo, sorry. >.<

Spaceman McConaughey

Glad I gave the OK on this being released. It's much better now. :D

*levels up*

Cid


Stray

Is there a way to make it with 4-8 sounds for each terrain?
Because always the same sound on a terrain is very annoying. As example: If there is a big area with the same terrain.

Annoying:
http://www.2shared.com/audio/OnpreM-G/Step_H1.html

Not so annoying:
http://www.2shared.com/audio/jAtsh7UX/Step_H2.html
I'm very grateful to you all for your great help.

G_G

Its possible. But it'd take a bit to do it. If I have the time after school today I'll try and do it.

Stray

Oh god, thank you so much for trying it!
I'm very grateful to you all for your great help.

Stray

I wanted to ask again...

also, is it able to make stepsounds for the npcs?
I'm very grateful to you all for your great help.

Vexus

Sorry for necropost but I'm having a small problem with this script.

I made a small event that makes your character move forward twice, play a sound effect and jump backwards and till there it works but when I move after the event the terrain no longer makes sounds when walking till I open/close menu or enter new map.

Anything I can do to fix it?

Also would be it too hard to have a script call that let's me change the wait for the sound so when your running the stepping sound goes faster and when your walking it goes back to what you write on the script?

Thanks
Current Project/s:

G_G

I'll look into it Vexux. Gimme about a week. xD My to-do list is getting pretty big.

Vexus

Sure np.

Thanks for adding it to the to-do list :)
Current Project/s:

toni112007

Hi all im new i have rpg maker xp and this does not work for me as i make this script and do what it says whenever i choose from 0-7 it says cannot find audio/se/fs "name of sound " when in game and game shuts down.

Landith

That means you need that file in your audio folder. So whatever 'name of sound' is put it in that folder 'GAME NAME/Audio/Se/Fs/' or whatever it specifies and you won't get that error anymore.

Blizzard

Just change them in the config.


  Terrains[0] = '001-System01'
 Terrains[1] = 'fs_wood_hard1'
 Terrains[2] = 'fs_grass03'
 Terrains[3] = 'fs_stone_hoof2'
 Terrains[4] = 'as_na_grassmove2'
 Terrains[5] = 'fs_water_hard1'
 Terrains[6] = 'fs_dirt_hard1'
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

toni112007

Do you know where are that sounds located? i cant find them anywhere :/
sorry im noob at rpg maker xp

G_G

In your project's folder. You place the sound effects in "Audio/SE/"

toni112007

I know that but i dont know where are these sound located
001-System01
fs_wood_hard1
fs_grass03
fs_stone_hoof2
as_na_grassmove2
fs_water_hard1
fs_dirt_hard1

I found only 001-system01,but i dont have others where can i get them?