[XP] Ambient SFX

Started by ForeverZer0, May 02, 2011, 12:39:09 am

Previous topic - Next topic

ForeverZer0

Ambient SFX
Authors: ForeverZer0
Version: 1.1
Type: Environment Add-on
Key Term: Environment Add-on



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

Click here for the script.
Spoiler: ShowHide

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# Ambient SFX
# Author: ForeverZer0
# Date: 5.1.2011
# Version: 1.1
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#
# Explanation:
#   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.
#
# Instructions:
#   - Set your maps up using this syntax:
#
#   when MAP_ID then [DELAY, ['SE_NAME', VOLUME, PITCH],
#     ['ANOTHER_SE_NAME', VOLUME, PITCH], ['ANOTHER_SE_NAME', VOLUME, PITCH]]
#
# The system will choose a random number between 0 - DELAY each frame (that
# is 40 times per second for those who don't know), and if that number is equal
# to 0, a random SE in the array will be played. You don't need to set up any
# maps if you are not using this system for it. 
#
# The system can be toggled ON/OFF with the script call:
#
#            $game_system.AMBIENT_SE = true/false
#
# It can also be temporarily added or changed with the script call:
#
#   $game_map.ambient_SE = [DELAY, ['SE_NAME', VOLUME, PITCH],
#     ['ANOTHER_SE_NAME', VOLUME, PITCH], ['ANOTHER_SE_NAME', VOLUME, PITCH]]
#
# ...or turned off temporarilly on the current map with:
#
#   $game_map.ambient_SE = nil
#
# These will only work on a temporary basis for the current map, everything will
# return to normal once the player moves to a different map. Disable the add-on
# completely if you don't want it to persist.
#
# Author's Notes:
#   Try to avoid using WAV files for the SFX. I have found that this can cause
#   lag occasionally when the SE is played. Use OGG or MIDI.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:

class Game_Map
 
  attr_accessor :ambient_SE

  alias zer0_ambient_sfx_setup setup
  def setup(map_id)
    @ambient_SE = case map_id
#-------------------------------------------------------------------------------
# BEGIN CONFIGURATION
#-------------------------------------------------------------------------------
    # You can add more than 1 map_id per case.     ex. (when 1, 8, 32)
    when 1
      [150, ['Birdsong1', 80, 100], ['Birdsong2', 80, 100],
      ['Birdsong3', 80, 100], ['Birdsong4', 80, 100]]
    when 2
      [40, ['Cricket', 80, 100], ['Frog', 80, 100]]
#-------------------------------------------------------------------------------
# END CONFIGURATION
#-------------------------------------------------------------------------------
    end
    zer0_ambient_sfx_setup(map_id)
  end
 
  alias zer0_ambient_sfx_upd update
  def update
    if $game_system.AMBIENT_SFX && @ambient_SE != nil
      if rand(@ambient_SE[0]) == 0
        r = rand(@ambient_SE.size - 1) + 1
        $game_system.se_play(RPG::AudioFile.new(*@ambient_SE[r]))
      end
    end
    zer0_ambient_sfx_upd
  end
end

#===============================================================================
# ** Game_System
#===============================================================================

class Game_System
 
  attr_accessor :AMBIENT_SFX
 
  alias zer0_ambient_sfx_init initialize
  def initialize
    zer0_ambient_sfx_init
    @AMBIENT_SFX = true
  end
end



Instructions

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


Compatibility

No known compatibility issues.


Credits and Thanks


  • ForeverZer0, for the script




Author's Notes

Try to avoid using WAV files for the SFX. I have found that this can cause lag occasionally when the SE is played. Use .OGG or .MIDI. Although RMXP does not support playing them streaming, their small file size and good compression make them good for such a thing.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Holyrapid

Sounds nice, i'm gonna check it out some time later...

Kise

April 25, 2015, 12:15:22 pm #2 Last Edit: April 25, 2015, 12:48:34 pm by Kise
Really good script :) But sometimes the same sound is played twice, is there any way to fix that? Im using seven sounds on map, so i don't thing it's just coincidence.

( Sorry for posting it here, I didn't wanted to create new theard for small thing like that )

ForeverZer0

If I remember correctly, it chooses the sound randomly from what is available, therefore it is possible the same sound can be used twice in a row. Although it is not often, it can happen. It would be like rolling a seven sided dice and getting the same number twice.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Kise

I know it is possible, but they're not playing in a row, they're playing almost at the same time. If it's really just coincidence, then sorry for bothering you.