Ambient Sound Effects

Ambient SFX Version: 1.1
By: ForeverZer0

Introduction

This system will play SE at intervals in addition to the BGM/BGS. You can configure each map separately with its own array of SE to play. The SE will played randomly and will be played at random intervals (configurable).

Features
  • Each map can be configured separately
  • Can use as many different SFX as you want for each map
  • Provides a more 'random' effect than a simple looping BGM/BGS
  • Temporary changes or enabling/disabling with script calls
  • Perfect for bird chirps, insect SFX, etc.

Screenshots

Kind of hard for sound effects...

Demo

Demo Link

Script

  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
Expand to see the code.


Instructions

Place script below Game_Map and above "Main". There are instructions for configuration in the script.

Compatibility

No known compatibility issues.

Author's Notes

Please report any bugs/issues so that they can be resolved. Enjoy!

Terms and Conditions

Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
Content Hidden Spoiler
You are free:

to Share - to copy, distribute and transmit the work
to Remix - to adapt the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

Noncommercial. You may not use this work for commercial purposes.

Share alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.

- For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.

- Any of the above conditions can be waived if you get permission from the copyright holder.

- Nothing in this license impairs or restricts the author's moral rights.
I really like the idea of this one, it'll be perfect for those larger maps. Great work and thanks for sharing :)

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=74933