Advertisement
ForeverZer0

[RMXP] Ambient SFX 1.1

May 21st, 2011
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.62 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Ambient SFX
  3. # Author: ForeverZer0
  4. # Date: 5.1.2011
  5. # Version: 1.1
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  7. #
  8. # Explanation:
  9. #   This system will play SE at intervals in addition to the BGM/BGS. You can
  10. #   configure each map separately with its own array of SE to play. The SE
  11. #   will played randomly and will be played at random intervals (configurable).
  12. #  
  13. # Features:
  14. #   - Each map can be configured separately
  15. #   - Can use as many different SFX as you want for each map
  16. #   - Provides a more 'random' effect than a simple looping BGM/BGS
  17. #   - Temporary changes or enabling/disabling with script calls
  18. #   - Perfect for bird chirps, insect SFX, etc.
  19. #
  20. # Instructions:
  21. #   - Set your maps up using this syntax:
  22. #
  23. #   when MAP_ID then [DELAY, ['SE_NAME', VOLUME, PITCH],
  24. #     ['ANOTHER_SE_NAME', VOLUME, PITCH], ['ANOTHER_SE_NAME', VOLUME, PITCH]]
  25. #
  26. # The system will choose a random number between 0 - DELAY each frame (that
  27. # is 40 times per second for those who don't know), and if that number is equal
  28. # to 0, a random SE in the array will be played. You don't need to set up any
  29. # maps if you are not using this system for it.  
  30. #
  31. # The system can be toggled ON/OFF with the script call:
  32. #
  33. #            $game_system.AMBIENT_SE = true/false
  34. #
  35. # It can also be temporarily added or changed with the script call:
  36. #
  37. #   $game_map.ambient_SE = [DELAY, ['SE_NAME', VOLUME, PITCH],
  38. #     ['ANOTHER_SE_NAME', VOLUME, PITCH], ['ANOTHER_SE_NAME', VOLUME, PITCH]]
  39. #
  40. # ...or turned off temporarilly on the current map with:
  41. #
  42. #   $game_map.ambient_SE = nil
  43. #
  44. # These will only work on a temporary basis for the current map, everything will
  45. # return to normal once the player moves to a different map. Disable the add-on
  46. # completely if you don't want it to persist.
  47. #
  48. # Author's Notes:
  49. #   Try to avoid using WAV files for the SFX. I have found that this can cause
  50. #   lag occasionally when the SE is played. Use OGG or MIDI.
  51. #
  52. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  53.  
  54. class Game_Map
  55.  
  56.   attr_accessor :ambient_SE
  57.  
  58.   alias zer0_ambient_sfx_setup setup
  59.   def setup(map_id)
  60.     @ambient_SE = case map_id
  61. #-------------------------------------------------------------------------------
  62. # BEGIN CONFIGURATION
  63. #-------------------------------------------------------------------------------
  64.     # You can add more than 1 map_id per case.     ex. (when 1, 8, 32)
  65.     when 1
  66.       [150, ['Birdsong1', 80, 100], ['Birdsong2', 80, 100],
  67.       ['Birdsong3', 80, 100], ['Birdsong4', 80, 100]]
  68.     when 2
  69.       [40, ['Cricket', 80, 100], ['Frog', 80, 100]]
  70. #-------------------------------------------------------------------------------
  71. # END CONFIGURATION
  72. #-------------------------------------------------------------------------------
  73.     end
  74.     zer0_ambient_sfx_setup(map_id)
  75.   end
  76.  
  77.   alias zer0_ambient_sfx_upd update
  78.   def update
  79.     if $game_system.AMBIENT_SFX && @ambient_SE != nil
  80.       if rand(@ambient_SE[0]) == 0
  81.         r = rand(@ambient_SE.size - 1) + 1
  82.         $game_system.se_play(RPG::AudioFile.new(*@ambient_SE[r]))
  83.       end
  84.     end
  85.     zer0_ambient_sfx_upd
  86.   end
  87. end
  88.  
  89. #===============================================================================
  90. # ** Game_System
  91. #===============================================================================
  92.  
  93. class Game_System
  94.  
  95.   attr_accessor :AMBIENT_SFX
  96.  
  97.   alias zer0_ambient_sfx_init initialize
  98.   def initialize
  99.     zer0_ambient_sfx_init
  100.     @AMBIENT_SFX = true
  101.   end
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement