Save-Point
Sound Related + More - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Code Support (https://www.save-point.org/forum-20.html)
+--- Thread: Sound Related + More (/thread-2908.html)



Sound Related + More - Yin - 03-30-2009

I know this is probably very easy to you big time scripters, but how would I go about fading a sound to a certain volume? I know bgm_fade(time),
but that doesn't include volume.

EDIT:
How would I go about editing this script to make time go by slower, I added / 5 to the @total_sec = Graphics.frame_count / Graphics.frame_rate and it seemed to have the correct effect, but it screws up the time for some reason.
ALSO, how come when I turn a switch on throught the script, the event on the map that it triggers does not show up. How do I update the map to show the switch changes? I mean it works when I have it in a conditional branch, but when I have it as a page condition it doesn't show.

The script

Code:
#==============================================================================
# ** Window_PlayTime + Day & Night Settings Script
#    Window_PlayTime Add-on
#    modified by shadowball
#    further modified for Yin by second_crimson
#    further modified by Yin to use game switches
#
#  On the Menu scene you'll see the current in-game day and time...
#==============================================================================

class Window_GameStats < Window_Base

def initialize
   super(0, 0, 160, 96)
   self.contents = Bitmap.new(width - 32, height - 32)
   refresh
end

def refresh
   self.contents.clear
   @total_sec = Graphics.frame_count / Graphics.frame_rate
   day = @total_sec / 60 / 24 % 7
   hour = @total_sec / 60 % 24
   minute = @total_sec % 60
   if hour >= 12
     meridian = " PM"
   else
     meridian = " AM"
   end
   if hour == 0 then hour = 12 end
   if hour > 12 then hour -= 12 end
   text = sprintf("%02d:%02d", hour, minute)
   text = text + meridian
   self.contents.font.color = system_color
   shb_day = 'Sunday'    if day == 0
   shb_day = 'Monday'    if day == 1
   shb_day = 'Tuesday'   if day == 2
   shb_day = 'Wednesday' if day == 3
   shb_day = 'Thursday'  if day == 4
   shb_day = 'Friday'    if day == 5
   shb_day = 'Saturday'  if day == 6
   shb_weekday = shb_day
   self.contents.draw_text(4, -10, 120, 32, shb_weekday, 0)
   self.contents.font.color = normal_color
   self.contents.draw_text(4, 4, 120, 32, text, 2)
  
   case $game_party.gold
   when 0..9999
     gold = $game_party.gold
   when 10000..99999
     gold = $game_party.gold.to_s
     array = gold.split(//)
     gold = array[0].to_s+array[1].to_s+","+array[2].to_s+array[3].to_s+array[4].to_s
   when 100000..999999
     gold = $game_party.gold.to_s
     array = gold.split(//)
     gold = array[0].to_s+array[1].to_s+array[2].to_s+","+array[3].to_s+array[4].to_s+array[5].to_s
   when 1000000..9999999
     gold = $game_party.gold.to_s
     array = gold.split(//)
     gold = array[0].to_s+","+array[1].to_s+array[2].to_s+array[3].to_s+","+array[4].to_s+array[5].to_s+array[6].to_s
   end
#Draw Gold
self.contents.font.color = system_color
gold_word = $data_system.words.gold.to_s
cx = contents.text_size(gold_word).width
cx2=contents.text_size(gold.to_s).width
self.contents.draw_text(4, 18, 120-cx-2, 32, gold_word)
self.contents.font.color = normal_color
self.contents.draw_text(124-cx2+1,32, cx2, 32, gold.to_s, 2)
self.contents.font.color = system_color
end

def update
   super
   if Graphics.frame_count / Graphics.frame_rate != @total_sec
     refresh
   end
end
end

#==============================================================================
#  *  Scene_Map - Modified
#     modified by shadowball
#
#  Screen tone will change depending on the in-game play time automatically
#==============================================================================
class Scene_Map
alias shb_map_up update
def update
   @total_sec = Graphics.frame_count / Graphics.frame_rate
   @shb_hour = @total_sec / 60 % 24
   if @shb_hour < 5 || @shb_hour > 18     # 7 p.m. - 5 a.m.
     $game_switches [11] = true
     $game_switches [12] = false
     $game_switches [13] = false
     $game_switches [14] = false
     $game_screen.start_tone_change(Tone.new(-120, -120, -120, 0), 1)
   elsif @shb_hour > 4 && @shb_hour < 7   # 5 a.m. - 7 a.m.
     $game_switches [12] = true
     $game_switches [11] = false
     $game_switches [13] = false
     $game_switches [14] = false
     $game_screen.start_tone_change(Tone.new(-40, -40, 0, 0), 1)
   elsif @shb_hour > 6 && @shb_hour < 16  # 7 a.m. - 4 p.m.
     $game_switches [13] = true
     $game_switches [12] = false
     $game_switches [11] = false
     $game_switches [14] = false
     $game_screen.start_tone_change(Tone.new(0, 0, 0, 0), 1)
   elsif @shb_hour > 15 && @shb_hour < 19 # 4 p.m. - 7 p.m.
     $game_switches [14] = true
     $game_switches [12] = false
     $game_switches [13] = false
     $game_switches [11] = false
     $game_screen.start_tone_change(Tone.new(30, 10, 0, 0), 1)
   end
   shb_map_up
end
end

#=======================================================
#  *  Game_System Add-on v 1.0
#     by shadowball
#     08.02.2008
#
#  You can set the time in minutes, hours, days
#  Syntax:  $game_system.set_time(0, 30, 2, 3)
#=======================================================
class Game_System
def set_time(alter = 0, minute = 0, hour = 0, day = 0)
   if minute >= 0
     if minute >= 60
       minute = 59
     end
     set_min = Graphics.frame_rate * minute
   end
   if hour >= 0
     if hour >= 24
       hour = 23
     end
     set_hour = Graphics.frame_rate * 60 * hour
   end
   if day >= 0
     if day >= 31
       day = 30
     end
     set_day = Graphics.frame_rate * 60 * 24 * day
   end
  
   case alter
   when 0 # sets the time
     Graphics.frame_count = 0 + set_day + set_hour + set_min
   when 1 # adds the hours, minutes you specified to the current in-game playtime
     Graphics.frame_count = Graphics.frame_count + set_day + set_hour + set_min
   when 2 # this one does exactly the opposite...
     Graphics.frame_count = Graphics.frame_count - set_day - set_hour - set_min
   end
end
end



[Resolved] Sound Related + More - DerVVulfman - 03-30-2009

Technically, that's a difficult one.

You see... if you look in the bgm_fade method in Game_System, there is a statement of:
Code:
Audio.bgm_fade
That statement refers to the AUDIO hidden class in RMXP itself.

Since it's a hidden class, we really don't have the actual code in which to make our own custom scripts. You may need to have someone create a script that uses the Windows Win32API to play that music file.


[Resolved] Sound Related + More - Yin - 03-30-2009

Yeah, you are right, so if I keep changing
Audio.bgm_play(filename[, volume[, pitch]]) for lower volumes will that work kind of like fade? Also, if I want it to keep the file that is playing, and just lower the volume, would I still have to put the filename in there?


[Resolved] Sound Related + More - DerVVulfman - 03-30-2009

Well, the filename is not optional, so you would have to supply it every time.

However, I cannot say that calling the same statement every time wouldn't just reset the music to start over every time. You could try it, but I cannot guarantee it would work the way you want.


[Resolved] Sound Related + More - Yin - 03-30-2009

Since this is my own topic, I didn't want to flood the board with a new post since it's already at the top. So here I modified my first post with another question.

EDIT: Okay, I think I figured out one part. The slow down part. I changed
minute = @total_sec % 60
to
minute = @total_sec % 60 / 5
Is that correct? It seems to be working fine, but I just want to be sure.
Now, all there is is figuring out why my switches won't update the map to show the triggered event.

FIXED: YAY! I fixed it by putting
$game_map.need_refresh = true
after each set of switch changes.

This topic is officially resolved and can be closed :)

EDIT: OK, never mind that. Topic unclosed!

Now when I manually try to tint screen, it doesn't work. What do I do?

FIXED: second_crimson from rmxp.org fixed it for me! Soooo okay, NOW this topic can be closed!


[Resolved] Sound Related + More - DerVVulfman - 04-04-2009

Glad ya got it going, Yin. Topic closed. ^_^