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.

BGS & SFX that get louder as you get closer

If this is was already made, could someone point me in the direction of it? I couldnt find it in the scripts listings. Anyways, what I'm looking for is a script that will allow Background Sounds (BGS) and Sound Effects (SFX) to become louder as you get closer to them on the map, and quieter when you get farther away from them. Preferably something that is usable for water and stuff like that where there are multiple tiles that the sounds would be coming from.

If that's not clear enough, hopefully this example will explain it a bit more:

Say you are in a cave that has a stream running through one side of the map. Instead of having the sounds the same loudness on the entire map, create a script (if possible) that will make the sounds become quieter when you are on the opposite side of the cave than the water, and as you walk closer to the stream of water, the sounds get louder until you are standing right next to it and it's at it's loudest (the loudest should be able to be set up by the script, instead of always being 100% for the volume).

I just thought this would be a cool script to have in any game, as it would add more realism to the game.

Please and thank you!
 
Hehe. Just answered this somewhere else.

I started a sound interaction system a while back but never finished it. Think you can help me think of a list of occurances where you would here sound?

I have object objects that constantly play a bgs and the volume changes by distance (you tell it max volume at distance = 1 and min volume and farthest distance).

I have stepping objects that me a SE when you step, and you can control the volume levels like in the first one or just simply play se with a set volume no matter the distance.

Any other ideas?
 
Nothing to say against one of your scripts, Seph, but I still think a 'more handy' version is the better solution... just like this little snippet of heaven:
Code:
sound = '013-Fire01'
dx = $game_player.x-$game_map.events[@event_id].x
dy = $game_player.y-$game_map.events[@event_id].y
d=Math.sqrt(dx.abs**2+dy.abs**2)
bgs=RPG::AudioFile.new(sound)
bgs.volume = [100-d*20,0].max
$game_system.bgs_play(bgs)
Well, it isn't working well with other events of the same kind on the same map, though... results in the first entity working perfectly, but everything beyond cracking... try it out and see...

BTW: Think of the MOM, Seph :P
 
SephirothSpawn;179025 said:
Hehe. Just answered this somewhere else.

I started a sound interaction system a while back but never finished it. Think you can help me think of a list of occurances where you would here sound?

I have object objects that constantly play a bgs and the volume changes by distance (you tell it max volume at distance = 1 and min volume and farthest distance).

I have stepping objects that me a SE when you step, and you can control the volume levels like in the first one or just simply play se with a set volume no matter the distance.

Any other ideas?

is this done? or are you still working on it?

a few things that could have sound:
water, birds (like get closer to an NPC bird flying around and the chirps get louder), waves (like at a beach), crowded areas (walk closer to an exit to a map that leads to a crowded area, and the voices of the people gets louder), etc... they arent great, cuz i cant think of many off the top of my head right now, but just a few things that would have sounds ;)


@Bluescope:
I'll try that method soon, i'm currently busy with some other work, so i dont have the time to get on RMXP right now.
 
@BlueScope: Or, rather than using that snippet all the time, you will just have a comment line and test to input. The script will take care of the rest. Which is simpler? Yes, I am feeling inspired to work on your MOM (XD) and might get a bit more done on that.

@swiftdeathsk: I will see what I can do with those suggestions. Just check my test bed in the .4 edition. It will be in there. It's on my list of things to do.
 
Well Seph, the problem with you uber-scripter's scripts is that you make 2000 lines with extra features around that part XD But well, considering I could do the call-the-code-I-posted-with-a-comment, you just have to do something to prove that you're better than the average scripter, don't you? :P

And for the MOM (man, I should've called this 'Object Organizer' or something XD ), I'll drop a little note here and there just to make sure XD
 
I'm no better than the average scripter, just dedicated to what I do. Yes, it is Trickster and I's calling card to throw in more features than you can shake a stick out for every script. Yes, this causes the code to be longer than needed, but then again, for what all it does/can do, it's worth it.

And you would need to have an event running constantly with call scripts, meaning you are using the Interpreter class to reduce runtime, but call scripts are evaluated from code with the eval, making it even slower. Reading comment lines mean you can just execute and perform all that within the actual classes, not the interpreter. Too few people release this and even over-use the call script function with auto-run/parellel process events, causing much more lag than is needing. Do this with several scripts and ugh.

:p
 
SephirothSpawn;179193 said:
I'm no better than the average scripter, just dedicated to what I do. Yes, it is Trickster and I's calling card to throw in more features than you can shake a stick out for every script. Yes, this causes the code to be longer than needed, but then again, for what all it does/can do, it's worth it.

And you would need to have an event running constantly with call scripts, meaning you are using the Interpreter class to reduce runtime, but call scripts are evaluated from code with the eval, making it even slower. Reading comment lines mean you can just execute and perform all that within the actual classes, not the interpreter. Too few people release this and even over-use the call script function with auto-run/parellel process events, causing much more lag than is needing. Do this with several scripts and ugh.

:p

so what you're saying is that it's much faster to use scripts that are run by having a comment in the event than having a parallel process event that has a call script command in it? If so, could you explain how to make it so that a script runs via comment? I dont know how to do that, and I'm still trying to learn RGSS while making my game. This would help me if you could explain just how it checks for the comment in the events.
 
I'll take this one... here's the code for checking an event's first line of comments. The other three have another way to check, which doesn't come into my mind right now... as the conditional states, the container 'event' must hold an entity of Game_Event in order to work. To prevent a read error, I'd suggest you include this statement in the conditional, too, such as I did:
Code:
if event.is_a?(Game_Event) and event.list != nil and event.list[0].code == 108 and event.list[0].parameters == ["Text"]
  # Stuff
end

@Seph: You and Trick not being better than the average scripter? Man, stop trying to be modest :P
 
Ok. Here's what I have so far.

Code:
#==============================================================================
# ** Sound Interaction System
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1
# 2007-03-21
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1 ---------------------------------------------------- (2007-03-21)
#------------------------------------------------------------------------------
# * Requirements :
#
#------------------------------------------------------------------------------
# * Description
#
#------------------------------------------------------------------------------
# * Instructions
#
#   Place The Script Below the SDK and Above Main.
#------------------------------------------------------------------------------
# * Customization
#
#------------------------------------------------------------------------------
# * Syntax :
#
#   Comment : Sound Interaction|type|filename|max_volume|max_distance
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Sound Interaction System', 'SephirothSpawn', 1, '2007-03-21')
SDK.check_requirements(2.2, [1, 2]) 

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Sound Interaction System')
  
#==============================================================================
# ** Sound Interaction System
#==============================================================================
  
module Sound_Interaction
  #--------------------------------------------------------------------------
  # * Player Movement SE
  #--------------------------------------------------------------------------
  Player_Movement_SE_Name   = '013-Move01'
  Player_Movement_SE_Volume = 60
  Player_Movement_SE_Frames = [0]
  #--------------------------------------------------------------------------
  # * Non-Defined Frames To Play Movement SE
  #--------------------------------------------------------------------------
  Movement_SE_Frames = [0]
end
  
#==============================================================================
# ** Game_Character
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :sis_movement_se_name
  attr_accessor :sis_movement_se_max_volume
  attr_accessor :sis_movement_se_max_distance
  attr_accessor :sis_movement_se_frames
  attr_accessor :sis_range_bgs_name
  attr_accessor :sis_range_bgs_max_volume
  attr_accessor :sis_range_bgs_max_distance
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_soundintsys_gmchr_ua, :update_animation
  #--------------------------------------------------------------------------
  # * Frame Update : Animation Counters
  #--------------------------------------------------------------------------
  def update_animation
    # Gets Old Pattern
    old_pattern = @pattern
    # Original Update Animation Counters
    seph_soundintsys_gmchr_ua
    # If Play Movement SE
    unless @sis_movement_se_name.nil?
      # If Pattern is Different
      if old_pattern != @pattern && 
         # If Movement SE Frame
         @sis_movement_se_frames.include?(old_pattern)
        # Gets Distance From Player
        px, py = $game_player.x, $game_player.y
        distance = self == $game_player ? 0 : Math.hypot(@x - px, @y - py)
        # Calculates Volume
        md = @sis_movement_se_max_distance 
        mv = @sis_movement_se_max_volume
        volume = distance == 0 ? mv : distance > md ? 0 : 
            mv * ((md - (distance - 1)) / md)
        # If Volume Greater Than 0
        if volume > 0
          # Play Movement SE
          Audio.se_play('Audio/SE/' + @sis_movement_se_name, volume) 
        end
      end
    end
  end
end  
  
#==============================================================================
# ** Game_Event
#==============================================================================

class Game_Event
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_soundintsys_gmevt_refrsh, :refresh
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Original Refresh
    seph_soundintsys_gmevt_refrsh
    # Set LD Variables
    @sis_movement_se_name         = nil
    @sis_movement_se_max_volume   = 100
    @sis_movement_se_max_distance = 10
    @sis_range_bgs_name           = nil
    @sis_range_bgs_max_volume     = 100
    @sis_range_bgs_max_distance   = 10
    # Return if Nil Page or Erased
    return if @list.nil? || @erased
    # Pass Through All Event Commands
    for ec in @list
      # If Comment Command
      if ec.code == 108 &&
         # And Comments Include "SOUND INTERACTION"
         ec.parameters[0].upcase.include?('SOUND INTERACTION')
        # Split Comment Line
        parameters = ec.parameters[0].split('|')
        # Branch By Type
        case parameters[1].upcase
        when 'MVT'
          # Set Filename, Volume & Distance
          @sis_movement_se_name         = parameters[2]
          @sis_movement_se_max_volume   = parameters[3].to_i
          @sis_movement_se_max_distance = parameters[4].to_i
          if parameters[5].nil?
            @sis_movement_se_frames = Sound_Interaction::Movement_SE_Frames
          else
            @sis_movement_se_frames     = eval "[#{parameters[5]}]"
          end
        when 'RNG'
          # Set Filename, Volume & Distance
          @sis_range_bgs_name           = parameters[2]
          @sis_range_bgs_max_volume     = parameters[3].to_i
          @sis_range_bgs_max_distance   = parameters[4].to_i
        end
      end
    end
  end
end

#==============================================================================
# ** Game_Player
#==============================================================================

class Game_Player
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :sis_range_bgs
  attr_accessor :sis_enabled
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_soundintsys_gmplyr_init,   :initialize
  alias_method :seph_soundintsys_gmplyr_update, :update
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Original Initialization
    seph_soundintsys_gmplyr_init
    # Enable Sound Interaction
    @sis_enabled = true
    # Set Movement Distances
    @sis_movement_se_name       = Sound_Interaction::Player_Movement_SE_Name
    @sis_movement_se_max_volume = Sound_Interaction::Player_Movement_SE_Volume
    @sis_movement_se_frames     = Sound_Interaction::Player_Movement_SE_Frames
    # Set Distances
    @sis_event_distances = {}
    @sis_event_distances.default = nil
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Original Update
    seph_soundintsys_gmplyr_update
    # Update Sound Interaction
    update_sound_interaction
  end
  #--------------------------------------------------------------------------
  # * Event Distances
  #--------------------------------------------------------------------------
  def sis_event_ranges
    # ditance => [event_id]
    ranges = {}
    for event_id in $game_map.events.keys.sort
      event = $game_map.events[event_id]
      next if event.sis_range_bgs_name.nil?
      distance = Math.hypot(@x - event.x, @y - event.y)
      ranges[distance] = [] unless ranges.has_key?(distance)
      ranges[distance] << event_id
    end
    return ranges
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Sound Interaction Range
  #--------------------------------------------------------------------------
  def update_sound_interaction
    # If Not Enabled
    unless @sis_enabled
      # If BGS Playing
      if @sis_range_bgs != nil
        # Set Range BGS to Nil
        @sis_range_bgs = nil
        # Stop BGS
        $game_system.bgs_play(nil)
      end
      return
    end
    # Gets Event Ranges
    event_ranges = sis_event_ranges
    # Set Main Break Flag to False
    main_break = false
    # Pass Through Shortest to Farthest Range
    for distance in event_ranges.keys.sort
      # Pass Through Events
      for event_id in event_ranges[distance].sort
        # If Last Event Played & Distance Hasn't Changed
        if @sis_range_last_event_id == event_id &&
           @sis_event_distances[event_id] == distance
          # Break Main Loop
          main_break = true
          # Break Loop
          break
        end
        # Gets Event Data
        event = $game_map.events[event_id]
        # If Distance Has Changed
        if @sis_event_distances[event_id] != distance
          # Record Distance Change
          @sis_event_distances[event_id] = distance
          # Calculates Volume
          md = event.sis_range_bgs_max_distance
          mv = event.sis_range_bgs_max_volume
          volume = distance == 0 ? mv : distance > md ? 0 : 
            mv * ((md - (distance - 1)) / md)
          # If Volume is Less Than 1
          if volume < 1
            # If Volume was Playing Before
            if @sis_range_bgs == event.sis_range_bgs_name
              # Set Previoius BGS to Nil
              @sis_range_bgs = nil
              # Clear SIS Last Event Range Flag
              @sis_range_last_event_id = nil
              # Stop BGS
              $game_system.bgs_play(nil)
            end
            next
          end
          # Record Playing BGS
          @sis_range_bgs = event.sis_range_bgs_name
          # Record SIS Last Event Range Flag
          @sis_range_last_event_id = event_id
          # Play BGS
          $game_system.bgs_play(RPG::AudioFile.new(@sis_range_bgs, volume))
          # Break Main Loop
          main_break = true
          # Break Loop
          break
        end
      end
      # Break if Break Main is True
      break if main_break
    end
  end
end

#==============================================================================
# ** Scene_Map
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_soundintsys_scnmap_cb,   :call_battle
  #--------------------------------------------------------------------------
  # * Frame Update : Call Battle
  #--------------------------------------------------------------------------
  def call_battle
    # If Player Playing Sound Interaction BGS
    if $game_player.sis_enabled && $game_player.sis_range_bgs != nil
      # Clear BGS
      $game_player.sis_range_bgs = nil
      # Stop BGS
      $game_system.bgs_play(nil)
    end
    # Original Call Battle
    seph_soundintsys_scnmap_cb
  end
end
  
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end

To make it work, just make a comment like:

Code:
Sound Interaction|RNG|013-Fire01|85|5

# Or

Sound Interaction|MVT|013-Move01|60|3

Basic syntax is

Sound Interaction|type|se_filename|max_volume|max_distance

Movements also have the option of a final

|frames

Which means for each post, 0, 1, 2, or 3 (unless you have more with a frame movement system), that when it changes from frame to frame, whenever it is on changes from those frames, it will play the SE.

Let me know if you guys have any other ideas.
 
I made a small modification to have different stepping sounds for each terrain. (Squishing swamps, splashing water, rustling leaves, etc.)

Replace lines 99 to 102 with:

Code:
#=================Txzeenath===========================================
#   Setup terrain specific walking sounds, simply add the sound filenames.
#   Filenames must be in order of the terrain number
#   For example: Below, the sound 001-System01 is assigned to terrain 0, while 002-System02 is assigned to terrain 1.
#   if I added another to the end, it would go to terrain 2, and so on.
#=====================================================================
            @terrain_sounds = ["001-System01", "002-System02"]
#====================================================================
        # If Volume Greater Than 0
        if volume > 0
          # Play Movement SE
          Audio.se_play('Audio/SE/'+@terrain_sounds[$game_map.terrain_tag($game_player.x, $game_player.y)], volume)

I'm working on them now, but once I get a set of footstep sounds for a variety of terrains finished, i'll put them up for download.
 
i apologize for bringing up an old thread, but i just seen this :].

The script works great, but i two questions.

Ok im my project the enemys play SFX inside of the "Custom movement" box.

they walk a few tiles, then make a SFX. is there anyway to make it so the sFX the events plays every couple of tiles has the same "get louder as you get closer" feature?

and my second question is, im sorry but i got a little confused :]
how did you say to make it a non-SDK script?

please help me out, and thank you!
:]
 

darkyy

Member

add a way to put what speed the sound should play like(comment syntax) that would help alot if you were to create a forrest with a bird in it, or a cow in the middle of a field so when you came closer you could hear it moo and not like moo,moo,moo,moo hehe
 
Great walking sound scripts I've searched through but all of them lacked either information or the features or even the help I think which is required:

The hear steps by arevullapo or whatever his name was, how do you get it to stop making sound if you dont want a moving event making a step sound? (E.G a bat making step noises without any legs :crazy: )

Also is there a way to turn off sound stepping using a call script command?
And lastly is there a way to change the default stepping sound using a call script command?

I think the terrrain idea is good but it would be good if there was a script that made events actually not make stepping sounds because not all random moving events have legs. Also not all random moving events are npc's or enemies! :mad:

Ok these are some things I think the scripters need to look at for thier future updates...
 

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