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.

A sound interaction script.

CJF

Member

Hello,

I was extremely interested in using SephirothSpawn's Sound Interaction System, but his laptop broke or something and he hasn't been around in a month. I'd still like to use his system, as it's great, but I can't get in touch with him. :( Anyways...

So right now I'm looking for a replacement script for my commercial game. Basically, his script* allow you to have sounds come from events and they'd get louder the closer you'd get to the object. The script could also be used to give characters footstep sounds.

Is there any other script out there that does this as well? If so, pretty please point me to it. Also, if anyone feels kind enough to actually script me such a system, that would be awesome and I'd be forever grateful and I'd give you a free copy of the game, credit and some money too if you wanted that(But who wants cash?;)).

Thanks a ton!

-CJF/LeonK

*Here is his script, if anyone wants to take a look.
#==============================================================================
# ** Sound Interaction System
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1
# 2007-03-21
# SDK : Version 2.0+, Parts I & II
#------------------------------------------------------------------------------
# * Version History :
#
#  Version 1 ---------------------------------------------------- (2007-03-21)
#------------------------------------------------------------------------------
# * Description
#
#  This script was designed to :
#    - play sound effects for moving characters and events on the map
#    - play background sound effects (bgs) when within range of events
#
#  When your player approaches an event with a walking sound effect, you will
#  here footsteps or other sound effects equal to the distance the player is
#  from the event. When the player gets within a range of an object with a
#  bgs, the bgs is played as the footsteps are played, just constantly.
#------------------------------------------------------------------------------
# * Instructions
#
#  Place The Script Below the SDK and Above Main.
#
#  Setting Events with Sound Interaction
#    - Comment : Sound Interaction|type|filename|max_volume|max_distance
#
#  Replace :
#    - type : MVT (for movement) or
#            RNG (for bgs)
#    - filename : filename of se or bgs
#    - max_volume : max volume
#    - max_distance : max distance
#------------------------------------------------------------------------------
# * Customization
#
#  Default player movement sound effect settings
#    - Player_Movement_SE_Name  = 'se_filename'
#    - Player_Movement_SE_Volume = max_volume
#    - Player_Movement_SE_Frames = [frame_id, ...]
#
#  Default events frames to play se
#    - Movement_SE_Frames = [frame_id, ...]
#------------------------------------------------------------------------------
# * Syntax :
#
#  Setting Sound Interaction Settings
#    <game_character>.sis_movement_se_name = 'filename' or nil
#    <game_character>.sis_movement_se_max_volume = n
#    <game_character>.sis_movement_se_max_distance = n
#    <game_character>.sis_movement_se_frames = [frame_id, ...]
#    <game_character>.sis_range_bgs_name = 'filename' or nil
#    <game_character>.sis_range_bgs_max_volume = n
#    <game_character>.sis_range_bgs_max_distance = n
#
#    NOTE : For events, when the event refreshes, these are all refreshed
#          by the page comments.
#
#  Setting Player Sound Interaction Settings
#    $game-player.sis_enabled = true or false
#==============================================================================

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

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Sound Interaction System')
 
#==============================================================================
# ** Sound Interaction System
#==============================================================================
 
module Sound_Interaction
  #--------------------------------------------------------------------------
  # * Player Movement SE
  #--------------------------------------------------------------------------
  Player_Movement_SE_Name  = nil
  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 && ![nil, ''].include?(@sis_movement_se_name)
          # 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
 
Well I don't need a copy of your game but I can at least fu-fill one of these 2 requests. I can get the footstep sound script for you I will post it below. It's just it doesn't have a radius of sound I don't think. Well lets cut to the chase below is the script. This also works for moving events not just the party. Hope it helps you :thumb:.

Code:
#==============================================================================
# ** Hear_Steps
#------------------------------------------------------------------------------
#  by arevulopapo
#  9.11.2006
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  attr_accessor :hear_steps
  attr_accessor :step_sound
  #--------------------------------------------------------------------------
  alias hs_init initialize
  def initialize
    hs_init
    @hear_steps = true
    @step_sound = "Audio/SE/walk01"
  end
  alias hs_update update
  def update
    if self.moving? and self.hear_steps == true and (Graphics.frame_count + 2 * self.id) % (18 - @move_speed) == 0
      if self.screen_x > 0 and self.screen_x < 640 and self.screen_y > 0 and self.screen_y < 480
        volume = 55 - 5 * Math.sqrt((self.x - $game_player.x)**2 + (self.y - $game_player.y)**2)
        Audio.se_play(@step_sound, volume, 55)
      end
    end
    hs_update
  end
end

EDIT: No credits for me please, but please give credit to Arevulopapo for this cool script. This doesn't need the sound interaction system but it still does somewhat of what is needed.
 

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