Advertisement
mjshi

Text Sound Effect (variation edit)

Sep 13th, 2015
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.17 KB | None | 0 0
  1. #==============================================================================
  2. # Text Sound Effect
  3. #------------------------------------------------------------------------------
  4. # by Zerbu
  5. # edited by mjshi for some variation :)
  6. #==============================================================================
  7. module Text_Sound_Effect
  8.   #--------------------------------------------------------------------------
  9.   # Configuration
  10.   #--------------------------------------------------------------------------
  11.   # The sound effect to play ("Name", Volume, Pitch)
  12.   # This can also be a filename without the file extension
  13.   # (i.e., beep.wav should be written as "beep")
  14.   MESSAGE_SOUND = RPG::SE.new("Knock", 100, 100)
  15.  
  16.   # The number of characters to display before each time the sound plays
  17.   # I recommend that you make this number at least 2 larger than the
  18.   # largest number in your variation.
  19.   MESSAGE_SOUND_FRAMES = 4
  20.  
  21.   # Variation decreases the number of characters displayed before the sound
  22.   # plays. Set to true to turn on, false to turn off.
  23.   VARY = true
  24.  
  25.   # Have multiple versions of the same number increases the chance of that
  26.   # specific delay occuring. It is not recommended to have variations
  27.   # above 2 seconds unless your message sound frames is super long or
  28.   # something.
  29.   VARIATION = [0, 0, 1, 1, 2]
  30.  
  31.   # Write a switch # here. Turn this switch on to disable sound effects.
  32.   # To disable this feature, type nil.
  33.   MESSAGE_SOUND_DISABLE = nil
  34.  
  35. end
  36.  
  37. class Window_Message < Window_Base
  38.   include Text_Sound_Effect
  39.   alias textsound_process_character_normal process_character
  40.   def process_character(c, text, pos)
  41.     if !MESSAGE_SOUND_DISABLE or !$game_switches[MESSAGE_SOUND_DISABLE]
  42.       if !defined?(@sound_frames)
  43.         @sound_frames = 0
  44.       end
  45.       if @sound_frames == 0
  46.         MESSAGE_SOUND.play
  47.       end
  48.       @sound_frames+=1
  49.       if @sound_frames == MESSAGE_SOUND_FRAMES and VARY == false
  50.         @sound_frames = 0
  51.       elsif @sound_frames == MESSAGE_SOUND_FRAMES and VARY == true
  52.         @sound_frames = VARIATION.sample
  53.       end
  54.     end
  55.     textsound_process_character_normal(c, text, pos)
  56.   end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement