Script: Sound Interaction System by SephirothSpawn
Conversion: <SDK> to <Non-SDK>
Thanks to anyone who is able to complete this task!
I posted it here, because it seems nobody even looks in the conversion request section. It had the same number of views as when I posted it.
Code:
#==============================================================================
# ** 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
Thanks to anyone who is able to complete this task!
I posted it here, because it seems nobody even looks in the conversion request section. It had the same number of views as when I posted it.