Dynamic Sound Emissions

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Best RPG Maker User - Engine2014 Most Unsung Member2013 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best RPG Maker User (Scripting)2011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best Use of Avatar and Signature Space2010 Favourite Staff Member2010 Most Mature Member
Dynamic Sound Emissions
Version: 1.0
Author: modern algebra
Date: August 27, 2007

Version History


  • Version 1.0: Original Script

Planned Future Versions

  • Version 1.5: Allow for in-game setting of a new sound emission object in a map
  • Version 2.0: Allow to have more than one sound emission object per map

Description


This script allows you to set an object in the map which emits a sound. What
this script does is set the volume of that sound according to how close you
are to the object. If you are far away, the sound will be faint, if you are
close the sound will be loud. Sorry, in this version there can be only one
object per map.

Features

  • Plays a BGS in increasing volume as you approach the object making the sound
  • Allows you to specifically set a radius for the sound (how many squares away you can hear the sound)
  • You can set up one of these objects for every map
  • Full customization from how big the object is to where it is located to the bgs that is played and the pitch

Instructions

Place this into it's own script above man. Find further instructions on setting up objects inside the editable region of the script

Script


Code: [Select]
#==============================================================================
#  Dynamic Sound Emissions
#  Version: 1.0
#  Author: Modern Algebra
#  Date: August 27, 2007
#------------------------------------------------------------------------------
#  Description:
#  This script allows you to set an object in the map which emits a sound. What
#  this script does is set the volume of that sound according to how close you
#  are to the object. If you are far away, the sound will be faint, if you are
#  close the sound will be loud. Sorry, in this version there can be only one
#  object per map.
#------------------------------------------------------------------------------
#  Instructions:
#  To set the objects which emit sound for each map, see below.
#------------------------------------------------------------------------------
# ** Data_Sound_Emission
#       This class holds all of the objects which emit any sound, for all maps
#==============================================================================

class Data_Sound_Emission
  #-------------------------------------------------------------------------
  # * Public Instance Variables
  #-------------------------------------------------------------------------
  attr_reader    :emissions
  #-------------------------------------------------------------------------
  # * Object Initialization
  #-------------------------------------------------------------------------
  def initialize
    @emissions = []
    #----------------------------------------------------------------------
    # * Editable Region
    #----------------------------------------------------------------------
    #  Place all sound emitting objects here. Write it like this:
    #
    #    @emissions[map_id] = Sound_Emission.new
    #    @emissions[map_id].setup (x,y,width,height,radius,bgs,pitch)
    #
    #  Where map_id is the ID of the map you want the object to appear on,
    #  x and y are the x and y positions of the upper-left corner of the object,
    #  width is the amount of squares in the x direction that the object covers,
    #  height is the amount of squares in the y direction that the object
    #  covers, radius is the number of squares away you want the sound to be
    #  hears, bgs is the bgs you want to play, and pitch is the pitch value
    #-----------------------------------------------------------------------
    @emissions[1] = Sound_Emission.new
    @emissions[1].setup (5,5,1,4,20,'011-Waterfall01',100)
    #-----------------------------------------------------------------------
    # * END Editable Region
    #-----------------------------------------------------------------------
  end
end
#==============================================================================
# ** Sound Emitting Object
#------------------------------------------------------------------------------
#  This class holds all the relevant data for the object which is emitting the
#  sound. It is accessed through $game_dynamic_sound_emission
#==============================================================================
class Sound_Emission
  #-------------------------------------------------------------------------
  # * Public Instance Variables
  #-------------------------------------------------------------------------
  attr_reader    :bgs
  attr_reader    :radius
  attr_reader    :pitch
  #-------------------------------------------------------------------------
  # * Object Initialization
  #-------------------------------------------------------------------------
  def setup (x, y, width, height, radius, bgs, pitch)
    @rect = Rect.new (x*128, y*128, (width-1)*128, (height-1)*128)
    @radius = radius*128
    @bgs = bgs
    @pitch = pitch
  end
  #-------------------------------------------------------------------------
  # * Volume
  #     Checks position to determine the appropriate volume.
  #-------------------------------------------------------------------------
  def volume (x, y)
    # Determine distance between position and the sound emitting object
    distance = [x - @rect.x, y - @rect.y]
    testers = [@rect.width, @rect.height]
    for i in 0...2 # For both the x distance and the y distance
      # Determine total distance in that direction from the object
      if distance[i] > 0  # IF you are to the right of the object
        # Take into account the width of the object
        if distance[i] <= testers[i] # If you are above or beside the object
          # Neglect the distance in that direction
          distance[i] = 0 
        else
          # Subtract the width to determine the closest row or column
          distance[i] -= testers[i]
        end
      else
        # Make the value positive
        distance[i] *= -1
      end
    end
    # Calculate the total distance
    total_distance = distance[0] + distance[1]
    ratio = (total_distance.to_f / @radius.to_f)*100 # Get the percentage
    ratio = [ratio,100].min
    ratio = 100 - ratio
    return ratio
  end
end

#==============================================================================
# ** Scene Title
#==============================================================================

class Scene_Title
  #-------------------------------------------------------------------------
  # * Alias Main to initialize the data class upon startup
  #-------------------------------------------------------------------------
  alias add_data_emissions main
  def main
    # Initialize $data_sound_objects
    $data_sound_objects = Data_Sound_Emission.new
    add_data_emissions
  end
end

#==============================================================================
# ** Game Player
#==============================================================================

class Game_Player
  #-------------------------------------------------------------------------
  # * Alias update to play the BGS
  #-------------------------------------------------------------------------
  alias update_volume update
  def update
    update_volume
    if $data_sound_objects.emissions[$game_map.map_id] != nil
      emitter = $data_sound_objects.emissions[$game_map.map_id]
      volume = emitter.volume (@real_x, @real_y)
      bgs = RPG::AudioFile.new (emitter.bgs,volume,emitter.pitch)
      if volume != 0
        $game_system.bgs_play (bgs)
      else
        Audio.bgs_stop
      end
    end
  end
end

Credit


  • modern algebra

Support


Will provide bug fixes and, if anyone can think of easy improvements to the script that I find beneficial, I will edit. I will also provide compatibility support

Known Compatibility Issues

There shouldn't be any, as nothing is overwritten. Maybe if another script uses the global variable $data_sound_objects.

Demo


See Attached.

Author's Notes

Very similar struccture to my Encounter Restrictions Script, and since someone requested one a long time ago (I made them an evented version), I figured I'd do it. I haven't been very productive lately, after all, and I wanted to make something new. Hopefully, one day I'll figure out how to play two bgses at the same time, I think I will have to make a manual play method though :(
« Last Edit: August 27, 2007, 05:32:16 AM by modern algebra »

*
Crew Slut
Rep:
Level 93
You'll love it!
For taking a crack at the RMRK Wiki
Very, very nice, very cool for a maze thing, where someone is lost, and you have to find them.

pokeball :)OfflineMale
********
Cheese
Rep:
Level 95
?
^^ your scripting is sweet!
Watch out for: HaloOfTheSun

***
Rep:
Level 88
Heh heh, thanks Modern.


Does RPG Maker use a 6 channel sound system? Because if so, then only two are used up.

If it does have compatibility with all 6 channels you could possibly use the 1 bgs and the two unused to make up to 3 BGSs play at the same time.
Games in progress:
Tome of Arastovia: 7% complete at 2 hours of gametime

**
Rep: +0/-0Level 86
Could you please make this be able to run multiple sounds, if you could please script that this would be perfect to work with ABS's monsters, making horrible noises that make them scarier ;). If you could please make this it would be great.


Current Games:
Darklands (Demon Slayer [new name])

Scripting - About 55% complete.

Eventing - About 1% complete.

Mapping - About .5% complete.

Spriting - 0% complete.

**
Rep: +0/-0Level 84
I get this when I try to test play

(I have never tried to edit a script before... lol

*
Rep:
Level 97
2014 Best RPG Maker User - Engine2014 Most Unsung Member2013 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best RPG Maker User (Scripting)2011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best Use of Avatar and Signature Space2010 Favourite Staff Member2010 Most Mature Member
3 Questions:

A) Is the script just above Main in the script Editor?
B) What do you mean by edit? As in you've tried to edit the script and then this error occured or as in you fear you are unable to fix the bug?
C) Are you in RMXP or RMVX?

**
Rep: +0/-0Level 84
I mean edit teh script section by adding anything to it, or even editing the little bit where you tell it what has what sound lol. I have NEVER touched teh script bit before. I have RPG maker XP and I think it is directly above, I will have to check tomorrow.

**
Rep:
Level 84
The Final Chapter
Awesome script, will definately use in my game! :D

Any idea when a new version will come out?

***
Rep:
Level 83
Look at me, runnin' and all
Project of the Month winner for August 2009
I was using this script in my game, but there's been some kind of.. error.

Every time I use the script, for example by a waterfall, it gives a giant lag. When you're in the range of the BGS, the whole project starts to lag like hell, the graphics are like turned upside down and the music is totally screwed up.

Anyone with this problem?
  - 

*
Rep:
Level 97
2014 Best RPG Maker User - Engine2014 Most Unsung Member2013 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best RPG Maker User (Scripting)2011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best Use of Avatar and Signature Space2010 Favourite Staff Member2010 Most Mature Member
That's a crazy problem. Care to upload it so that I can have a look?

***
Rep:
Level 69
RMRK Junior
Any chance of this script getting updated to 2.0?

Im hoping to find a Dynamic Sound Script that allows for Multiple Dynamic Sounds using Events as the Sound Emitters per Event PAGE (so they can be enabled / disabled / different sound settings).  Also maybe useful would be "Hot Spots" where in a certain distance, volume is at 100% of volume setting, outside of "Hot Spot" would be a "Falloff Range".  Also hopefully doable would be to allow "Overlap" of Dynamic Sound Emitters so two dynamic sounds could play at the same time.  Not sure if this is possible.  The features in "Dynamic Sound Emitting Areas/Events" seem to be perfect, but no workie jerkie on XP due to Areas.

Ryex's Dynamic Sounds for XP are cool, but it has some limitations.  Play BGS the default way (non Dynamic) does not work at all.  There is no overlap for Dynamic Sounds.  There is very little support offered for that script through maintenance.  If this script is updated, I think it could be the premiere Sound Emitter script for the XP community.

So is an Update possible?
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!

*
i am satin die lol
Rep:
Level 96
welcom to hel
GIAW 14: 2nd Place (Hard Mode)2013 Biggest Drama Whore2013 Zero to HeroParticipant - GIAW 11Secret Santa 2013 ParticipantFor taking arms in the name of your breakfast.
Thanks for the script, man.

Spoiler for:
Instructions

Place this into it's own script above man. Find further instructions on setting up objects inside the editable region of the script

But seriously, this is a cool script. It would be useful for some kind of hidden item side quest. "You'll hear the crystals buzzing if they're nearby" or something.

***
Rep:
Level 69
RMRK Junior
Thats actually a good idea for a practical application of the script.  Could be used in a huge variety of ways.  For example, campfires, waterfalls, streams, NPC monsters, windy bridges, waves crashing, car approaching, wildlife, etc.  Also could be used to make a sound effect "fade in" by running a cutscene and having a Sound Emitter get closer to the player, since XP has a fade out, but no fade in for sounds.

Sound is the often forgotten about "other half" of video games, and sounds are very often neglected when compared to visuals.
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!

*
Rep:
Level 97
2014 Best RPG Maker User - Engine2014 Most Unsung Member2013 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best RPG Maker User (Scripting)2011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best Use of Avatar and Signature Space2010 Favourite Staff Member2010 Most Mature Member
Sorry for neglecting this so much. I haven't scripted for XP for a long time, but it might be fun to go back and fix this script. I am somewhat embarrassed to look at my code though (this was one of my first scripts I think).

Anyway, I haven't had a lot of time for scripting lately, but if you're still interested I will try to get it done. Are the features in the VXA version of this script fine?

***
Rep:
Level 69
RMRK Junior
I don't have VX or Ace, so not entirely sure, but Im definitely hoping for a better sound script than Ryex's.  Not that its bad, but its limited.  I am hoping that multiple dynamic and static sound sources are possible.  Ryex's Dynamic Sounds has a few bugs, like changing a maps Background Sound from an Event.  As far as Multiple Background Sounds, maybe another approach would be to use a Looping Sound Effect since the engine can play multiple sound effects at the same time, but not multiple BGS.

Keeping my fingers crossed...
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!