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.

[Resolved]Conversion Request

Yin

Member

Script: Sound Interaction System by SephirothSpawn
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
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.
 
In all honesty, only ONE thing I see in this script requires SDK and thats Game_Character.update_animation (the origional method Game_Character.update is split into 8 methods so you can append additiona coding to them individually.) There's two ways you can do this,

Plan A : Use the minimum requirements for script

The first way would to paste just these 2 sections into your script editor below Scene_Debug and above anything else that is below it. Its not the ENTIRE SDK just the minimum required parts for this script.

Click *here*, the code is too big to post
Code:
#==============================================================================

# ** Enable Part II Check

#==============================================================================

if SDK::Parts.include?(2) || 

   SDK::Indidual_Parts.include?('GAME_CHARACTER#UPDATE')

 

#==============================================================================

# ** Game_Character

#------------------------------------------------------------------------------

#  This class deals with characters. It's used as a superclass for the

#  Game_Player and Game_Event classes.

#==============================================================================

 

class Game_Character

  #--------------------------------------------------------------------------

  SDK.log_branch(:Game_Character, :update, :update_movement_type, 

    :update_animation, :update_wait?, :update_force?, :update_startlock?, 

    :update_movement)

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    update_movement_type                      # Update Movement Type

    update_animation                          # Update Animation Counters

    return if update_wait?                    # Update Wait Test

    return if update_force?                   # Update Force Route Test

    return if update_startlock?               # Update Start/Lock Test

    update_movement                           # Update Movement

  end

  #--------------------------------------------------------------------------

  # * Frame Update : Movement Type

  #--------------------------------------------------------------------------

  def update_movement_type

    # Branch with jumping, moving, and stopping

    if jumping?

      update_jump

    elsif moving?

      update_move

    else

      update_stop

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update : Animation Counters

  #--------------------------------------------------------------------------

  def update_animation

    # If animation count exceeds maximum value

    # * Maximum value is move speed * 1 taken from basic value 18

    if @anime_count > 18 - @move_speed * 2

      # If stop animation is OFF when stopping

      if not @step_anime and @stop_count > 0

        # Return to original pattern

        @pattern = @original_pattern

      # If stop animation is ON when moving

      else

        # Update pattern

        @pattern = (@pattern + 1) % 4

      end

      # Clear animation count

      @anime_count = 0

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update : Wait Test

  #--------------------------------------------------------------------------

  def update_wait?

    # If waiting

    if @wait_count > 0

      # Reduce wait count

      @wait_count -= 1

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Frame Update : Force Route Test

  #--------------------------------------------------------------------------

  def update_force?

    # If move route is forced

    if @move_route_forcing

      # Custom move

      move_type_custom

      return true

    end

    return false

  end

  #--------------------------------------------------------------------------

  # * Frame Update : Starting or Lock Test

  #--------------------------------------------------------------------------

  def update_startlock?

    # When waiting for event execution or locked

    return (@starting or lock?)

  end

  #--------------------------------------------------------------------------

  # * Frame Update : Movement

  #--------------------------------------------------------------------------

  def update_movement

    # If stop count exceeds a certain value (computed from move frequency)

    if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)

      # Branch by move type

      case @move_type

      when 1  # Random

        move_type_random

      when 2  # Approach

        move_type_toward_player

      when 3  # Custom

        move_type_custom

      end

    end

  end

end

 

#==============================================================================

# ** Ends Enable Part II Check

#==============================================================================

end

Plan B : Overwrite the entire Game_Character.update

OR another way you could go about it, delete the entire "class Game_Character... end" section in the script and paste this over it...

Code:
class Game_Character

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Branch with jumping, moving, and stopping

    if jumping?

      update_jump

    elsif moving?

      update_move

    else

      update_stop

    end

    # Gets Old Pattern

    old_pattern = @pattern

    # If animation count exceeds maximum value

    # * Maximum value is move speed * 1 taken from basic value 18

    if @anime_count > 18 - @move_speed * 2

      # If stop animation is OFF when stopping

      if not @step_anime and @stop_count > 0

        # Return to original pattern

        @pattern = @original_pattern

      # If stop animation is ON when moving

      else

        # Update pattern

        @pattern = (@pattern + 1) % 4

      end

      # Clear animation count

      @anime_count = 0

      # 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

    # If waiting

    if @wait_count > 0

      # Reduce wait count

      @wait_count -= 1

      return

    end

    # If move route is forced

    if @move_route_forcing

      # Custom move

      move_type_custom

      return

    end

    # When waiting for event execution or locked

    if @starting or lock?

      # Not moving by self

      return

    end

    # If stop count exceeds a certain value (computed from move frequency)

    if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)

      # Branch by move type

      case @move_type

      when 1  # Random

        move_type_random

      when 2  # Approach

        move_type_toward_player

      when 3  # Custom

        move_type_custom

      end

    end

  end

end

Also, obviously you'll need to delete the SDK.log, SDK.enabled?() test as well as the last end in the script.

So long as there isn't any other scripts that overwrite Game_Character.update, this second way will be fine. Any script that aliases Game_Character's update method needs to be pasted BELOW this one to work. If you have any questions what I mean when I'm talking about scripts that "overwrite" and scripts that "alias" let me know.
 

Yin

Member

I tried plan B and it gave me an error. I was testing in a New Project.
undefined method sis_range _bgs_name for #game event bunch of numbers
Line 284 which is :
next if event.sis_range_bgs_name.nil?
I'll try plan A

EDIT:
Plan A worked, I'm now going to try it in my game.
EDIT:
YAY, Works wonder! Thank you!
 

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