Jump to content
Rpg²S Forum

Ambient Sound 1.0


mikb89
 Share

Recommended Posts

Ambient Sound

Descrizione

 

Con questo script puoi impostare gli eventi per riprodurre suoni se accanto al giocatore, variando volume, pitch, ecc.

Puoi anche personalizzare gli effetti cambiando le caratteristiche audio, via codice.

Per usare questo script bisogna configurare nello script gli effetti, quindi scriverne solo il nome in un commento nella pagina dell'evento voluto.

 

Autore

 

mikb89

 

 

Allegati

 

Demo multilingua v. 1.0 (257KB)

 

 

Istruzioni per l'uso

 

Copiare lo script normalmente sotto Modules e sopra Main, quindi configurare gli effetti voluti.

 

 

Script

 

# Ambient Sound v. 1.0
# VX version
# by mikb89

# Dettagli:
#  Le possibilità audio di RPG Maker fanno schifo. C'è questo Audio Pump
#   Up - FMOD Ex (script che estende il sistema audio usando le librerie FMod)
#   e lo menzionerò pressoché ovunque qui e lì nella demo. Comunque questo
#   script funziona lo stesso anche senza aggiungerlo.
#  Quello che QUESTO script fa penso sia chiaro. Puoi impostare gli eventi per
#   riprodurre suoni se accanto al giocatore, variando volume, pitch, ecc.
#  Puoi anche personalizzare gli effetti, come quello sotto del gallo, cambiando
#   le caratteristiche audio, via codice.
#  Per usare questo script bisogna configurare QUI gli effetti, quindi scriverne
#   il nome in un commento nella pagina dell'evento voluto.

# Configurazioni:
module AMBISOUND
 # Impostazioni se usi Audio Pump Up - FMOD Ex.
   SOUND_CHANNEL = 3
    # Canale da usare per ogni suono. Metti 0 o negativo per disattivare.
   USE_PAN = true # Vuoi sentire i suoni da vero sistema stereo?
    # Es. se un suono viene da destra, si sentirà di più nella cassa destra.
   # Fine della configurazione APU.

 DELAY = 10
  # Consente di non aggiornare l'audio troppo spesso. Più grande il numero,
  #  minore il lag.
 EFFECTS = {
 #"name"    => ["TYPE", "filename", max_vol, pitch, range, vol_min, :def]
  "radio"   => ["BGM",  "Airship",  100,     100,   8,     10,      nil], # <- metti , finché non è l'ultimo
  "radioLow"=> ["BGM",  "Airship",  70,      100,   2,     0,       nil],
  "chicken" => ["SE",   "Chicken",  80,      80,    3,     0,       :chicken],
  "tremolo" => ["BGS",  "Wind",     80,      100,   5,     0,       :tremolo]
 }
 # Spiegazione:
 # "name" è quel che andrai a scrivere nel commento per usare l'effetto.
 # "TYPE" è uno fra "BGM", "BGS", "ME", "SE".
 # "filename" è il nome del file che vuoi ascoltare.
 # max_volume è il massimo volume che il suono può raggiungere.
 #  cioè quando il pg è sopra l'evento.
 # pitch è il pitch. Standard per BGM/BGS è 100, per ME/SE è 80.
 # range è la distanza massima in cui è possibile udire il suono.
 # volume_min è il volume minimo da avere per far partire il suono. Se il pg è
 #  nei limiti del range, ma il volume sarebbe minore di questo valore, l'audio
 #  non partirà, in modo da lasciar dissolvere meglio il precedente.
 # :def ti lascia creare una funzione per gestire l'audio. Puoi sceglierne una
 #  fra quelle di default o aggiungerne se te la cavi con gli script.

 # def di esempio
 def self.chicken(sound) # pollo! o qualcosa di simile
   return unless sound # sound è nil quando la def viene chiamata come stop.
    # scriviamo return perché non è necessario stoppare un se.
   if (@last_chick ||= 0) >= 4+rand(6) # evita di riprodurre ogni volta
     @last_chick = 0
     pitchange = rand(20)-10 # pitch cambiato a caso
     sound.pitch += pitchange
     volchange = rand(1) == 0 ? rand(30)-10 : sound.volume*-1 # evitiamo ancora (volume 0)
     sound.volume += volchange
     sound.play # DOBBIAMO chiamare questo per riprodurre il suono
   else
     @last_chick += 1
   end
 end

 def self.tremolo(sound) # questo esempio richiede Audio Pump Up - FMOD Ex
   return if !$imported || !$imported[:mikb89_apu_fmod]
   unless sound # fermiamo il suono
     return unless @trem_chan # il canale è nil???
     FMod.bgs_stop(@trem_chan) # stop
     return # ci fermiamo
   end
   return if (@last_tremolo_volume ||= sound.volume) == sound.volume
   @last_tremolo_volume = sound.volume # ultimo volume
    # evitiamo di riprodurre lo stesso bgs allo stesso volume (questo è default
    #  per bgm e bgs quando non sono specificate def)
   cv = APU::CURRENT_CHANNEL_VARIABLE # variabile canale da opzioni APU
   var = @trem_chan = $game_variables[cv] # canale corrente
   $game_variables[cv] = @trem_chan = APU::MAX_CHANNELS - 1 if var < 1
   add_eff = true # tremolo già aggiunto?
    # se il canale corrente è 0 usiamo l'ultimo, quindi:
   sound.play # prima riproduciamo il BGS (vedi documentazione APU)
   for e in 0...FMod.bgs_DSP(@trem_chan)
     t = FModEx::FMOD_DSP_TYPES[FMod.bgs_getType(@trem_chan, e)]
     if t.downcase == "tremolo" # se tremolo esiste
       add_eff = false # non aggiungerlo
       break
     end
   end
   FMod::Audio.bgs_add_effect("tremolo", @trem_chan) if add_eff
    # aggiungiamo il DSP se necessario
   $game_variables[cv] = var if var < 1 # ripristiniamo il canale
 end
end

#Codename: ambisound

($imported ||= {})[:mikb89_ambisound] = true

# Licenza:
# - Puoi chiedermi di includere il supporto per altri script, a patto che usino
#   il $imported[script] = true;
# - Puoi modificare e anche ripostare i miei script, dopo una mia risposta. Per
#   ripostarli, comunque, devi aver fatto pesanti modifiche o porting, non puoi
#   fare un post con lo script così com'è;
# - Puoi usare i miei script per fare quel che vuoi, da giochi gratis a liberi
#   a commerciali. Apprezzerei comunque essere messo al corrente di quello che
#   stai creando;
# - Devi creditarmi, se usi questo script o parte di esso.

class Game_Event
#class Game_Event#def get_audio(spn)
 def get_audio(spn)
   audio_eff = (spn[1] == "" ||
                 spn[2] <= 0) ? nil :
                 case spn[0]
                 when "BGM"; RPG::BGM.new(spn[1], spn[2], spn[3])
                 when "BGS"; RPG::BGS.new(spn[1], spn[2], spn[3])
                 when "ME"; RPG::ME.new(spn[1], spn[2], spn[3])
                 when "SE"; RPG::SE.new(spn[1], spn[2], spn[3])
                 end
 end
 alias_method(:setup_b4_ambisound, :setup) unless method_defined?(:setup_b4_ambisound)
#class Game_Event#def setup(new_page) <- aliased
 def setup(new_page)
   setup_b4_ambisound(new_page)
   @sound_type = ""
   @last_volume = 0
   if @list != nil
     for par in @list
       if [408, 108].include?(par.code) && AMBISOUND::EFFECTS.has_key?(par.parameters[0])
         @sound_type = par.parameters[0]
       end
     end
   end
 end
 alias_method(:updateGE_b4_ambisound, :update) unless method_defined?(:updateGE_b4_ambisound)
#class Game_Event#def update() <- aliased
 def update
   updateGE_b4_ambisound
   if (@sdelay ||= AMBISOUND::DELAY) == 0
     @sdelay = nil
     var = nil
     if @sound_type != ""
       xv = $game_map.adjust_x(@real_x) - $game_map.adjust_x($game_player.real_x)
       yv = $game_map.adjust_y(@real_y) - $game_map.adjust_y($game_player.real_y)
       v = Math.hypot(xv/256.0, yv/256.0)
       if v <= AMBISOUND::EFFECTS[@sound_type][4]
         if @ae_playing
           spn = AMBISOUND::EFFECTS[@sound_type][0..3]
           spn[2] *= 1 - v/AMBISOUND::EFFECTS[@sound_type][4]
           met = AMBISOUND::EFFECTS[@sound_type][6]
           if @last_volume != spn[2] || met
             @last_volume = spn[2]
             if spn[2] >= AMBISOUND::EFFECTS[@sound_type][5]
               at = get_audio(spn)
               # REQUIRE Audio Pump Up - FMOD Ex
                 if $imported[:mikb89_apu_fmod] && AMBISOUND::SOUND_CHANNEL > 0
                   var = $game_variables[APU::CURRENT_CHANNEL_VARIABLE]
                   $game_variables[APU::CURRENT_CHANNEL_VARIABLE] = AMBISOUND::SOUND_CHANNEL
                 end
               # END REQUIRE
               if at != nil
                 if met
                   AMBISOUND.method(met).call(at)
                 else
                   at.play
                   # REQUIRE Audio Pump Up - FMOD Ex
                     if $imported[:mikb89_apu_fmod] && AMBISOUND::USE_PAN && $game_variables[APU::CURRENT_CHANNEL_VARIABLE] > 0
                       pan = 1.0 * case $game_player.direction
                             when 2; -xv; when 8; xv
                             when 4; yv; when 6; -yv; else; 0; end
                       pan /= AMBISOUND::EFFECTS[@sound_type][4]
                       if pan != 0
                         case AMBISOUND::EFFECTS[@sound_type][0]
                         when "BGM"; FMod.bgm_set_pan(pan, $game_variables[APU::CURRENT_CHANNEL_VARIABLE])
                         when "BGS"; FMod.bgs_set_pan(pan, $game_variables[APU::CURRENT_CHANNEL_VARIABLE])
                         when "ME"; FMod.me_set_pan(pan, $game_variables[APU::CURRENT_CHANNEL_VARIABLE])
                         when "SE"; FMod.se_set_pan(pan, $game_variables[APU::CURRENT_CHANNEL_VARIABLE], 0)
                         end
                       end
                     end
                   # END REQUIRE
                 end
               end
               # REQUIRE Audio Pump Up - FMOD Ex
                 $game_variables[APU::CURRENT_CHANNEL_VARIABLE] = var if var != nil
               # END REQUIRE
             end
           end
         else
           if @audiowait
             @audiowait -= 1
             @ae_playing = !(@audiowait = false) if @audiowait == 0
           else
             at = get_audio(AMBISOUND::EFFECTS[@sound_type])
             # REQUIRE Audio Pump Up - FMOD Ex
               if $imported[:mikb89_apu_fmod] && AMBISOUND::SOUND_CHANNEL > 0
                 var = $game_variables[APU::CURRENT_CHANNEL_VARIABLE]
                 $game_variables[APU::CURRENT_CHANNEL_VARIABLE] = AMBISOUND::SOUND_CHANNEL
               end
             # END REQUIRE
             if var != nil
               # REQUIRE Audio Pump Up - FMOD Ex
                 FMod::Audio.bgm_fade(20*AMBISOUND::DELAY, AMBISOUND::SOUND_CHANNEL) if at.class == RPG::BGM
                 FMod::Audio.bgs_fade(20*AMBISOUND::DELAY, AMBISOUND::SOUND_CHANNEL) if at.class == RPG::BGS
               # END REQUIRE
             else
               @ex_audio = at.class.last if [RPG::BGM, RPG::BGS].include?(at.class)
             end
             if @ex_audio != nil
               @ex_audio.class.fade(40*AMBISOUND::DELAY)
               @audiowait = 4
             else
               @ae_playing = true
             end
             # REQUIRE Audio Pump Up - FMOD Ex
               $game_variables[APU::CURRENT_CHANNEL_VARIABLE] = var if var != nil
             # END REQUIRE
           end
         end
       else
         @ae_playing = false
         met = AMBISOUND::EFFECTS[@sound_type][6]
         # REQUIRE Audio Pump Up - FMOD Ex
           if $imported[:mikb89_apu_fmod] && AMBISOUND::SOUND_CHANNEL > 0
             var = $game_variables[APU::CURRENT_CHANNEL_VARIABLE]
             $game_variables[APU::CURRENT_CHANNEL_VARIABLE] = AMBISOUND::SOUND_CHANNEL
           end
         # END REQUIRE
         if @ex_audio
           @ex_audio.play if [RPG::BGM, RPG::BGS, RPG::ME].include?(@ex_audio.class)
           @ex_audio = nil
           AMBISOUND.method(met).call(nil) if met
         else
           AMBISOUND.method(met).call(nil) if met
           if !met && var != nil
             t = AMBISOUND::EFFECTS[@sound_type][0]
             # REQUIRE Audio Pump Up - FMOD Ex
               FMod::Audio.bgm_fade(20*AMBISOUND::DELAY, AMBISOUND::SOUND_CHANNEL) if t.upcase == "BGM"
               FMod::Audio.bgs_fade(20*AMBISOUND::DELAY, AMBISOUND::SOUND_CHANNEL) if t.upcase == "BGS"
             # END REQUIRE
           end
         end
         # REQUIRE Audio Pump Up - FMOD Ex
           $game_variables[APU::CURRENT_CHANNEL_VARIABLE] = var if var != nil
         # END REQUIRE
       end
     elsif @ae_playing
       @ae_playing = false
       # REQUIRE Audio Pump Up - FMOD Ex
         if $imported[:mikb89_apu_fmod] && AMBISOUND::SOUND_CHANNEL > 0
           var = $game_variables[APU::CURRENT_CHANNEL_VARIABLE]
           $game_variables[APU::CURRENT_CHANNEL_VARIABLE] = AMBISOUND::SOUND_CHANNEL
         end
       # END REQUIRE
       if @ex_audio
         @ex_audio.play if [RPG::BGM, RPG::BGS, RPG::ME].include?(@ex_audio.class)
         @ex_audio = nil
       end
       # REQUIRE Audio Pump Up - FMOD Ex
         $game_variables[APU::CURRENT_CHANNEL_VARIABLE] = var if var != nil
       # END REQUIRE
     end
   else
     @sdelay -= 1
   end
 end
end

 

Visibile anche

 

 

Bugs e Conflitti Noti

 

N/A

 

 

Altri Dettagli

 

Consiglio di usarlo in combinazione con
script.
Edited by mikb89

Script!

 

Roba scritta, guide:

 

Applicazioni:

 

Progetti!

http://img69.imageshack.us/img69/2143/userbarctaf.png http://img641.imageshack.us/img641/5227/userbartemplateb.pnghttp://i46.tinypic.com/ac6id0.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...