• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Music changes according to time of day?

Minokun

The Rival in Space
107
Posts
10
Years
    • Seen Sep 18, 2019
    I noticed that in the Game the music changes in some maps from when it was night and then changed it back when it was day. I looked on the wiki but the article I was looking for didn't exist (Literally), and I don't think any NPC explains this in the Game either. Any help?
    (Btw, if there is another article or NPC that Does explain this and I'm an idiot please just tell me.)
     
    32
    Posts
    10
    Years
    • Seen Nov 19, 2016
    Hello!

    Have you tried looking at which map does this and what songs they play? Have you also tried looking at your Materialbase and did you notice two identical audio files called "021-Field04" and "021-Field04n"?

    You said you noticed a map that had a changing background. If you go to that map's properties, you'll notice it will read that it is using one of the BGM files I'm referring to. This is the "regular BGM". When any BGM has "n" at the end of its filename contained in the BGM folder, that song will be played when night occurs and will revert during the day. If "021-Field04n" does not exist, then no night BGM will play.

    If you wish to know why that is, look at this. This snippet is contained in Game_Map_

    No worries! It's not exactly explained in the Wiki but at least it is possible!
    Hope this helps!

    Code:
     #-----------------------------------------------------------------------------
      # * Autoplays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplayAsCue
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
          else
            pbCueBGM(@map.bgm,1.0)
          end
        end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end
     
    Last edited:

    Minokun

    The Rival in Space
    107
    Posts
    10
    Years
    • Seen Sep 18, 2019
    Hello!

    Have you tried looking at which map does this and what songs they play? Have you also tried looking at your Materialbase and did you notice two identical audio files called "021-Field04" and "021-Field04n"?

    You said you noticed a map that had a changing background. If you go to that map's properties, you'll notice it will read that it is using one of the BGM files I'm referring to. This is the "regular BGM". When any BGM has "n" at the end of its filename contained in the BGM folder, that song will be played when night occurs and will revert during the day. If "021-Field04n" does not exist, then no night BGM will play.

    If you wish to know why that is, look at this. This snippet is contained in Game_Map_

    No worries! It's not exactly explained in the Wiki but at least it is possible!
    Hope this helps!

    Code:
     #-----------------------------------------------------------------------------
      # * Autoplays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplayAsCue
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
          else
            pbCueBGM(@map.bgm,1.0)
          end
        end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end

    DUUUUUUUUUUUUUUUUUUH! Thanks, I'm such an idiot.
     
    15
    Posts
    13
    Years
    • Seen Aug 9, 2016
    I want to add conditions for morning and afternoon.
    How would I do this without incurring a Syntax Error in Game_Map?
     
    115
    Posts
    9
    Years
    • Seen Nov 17, 2023
    I was actually just about to ask about this as well. Although, I would rather not go through the hassle of having two of every piece of music cluttering up my audio folder.


    Is there a way where I could just adjust the pitch of my existing music based on the time of day? I was planning on playing my music at a normal pitch during the day, and a lower pitch at night. I already tried doing this through events, and while it works somewhat, it lags the game a ton when I try adding more and more events for each town and route. Is there another way to do this through scripting?
     
    Last edited:
    91
    Posts
    14
    Years
    • Seen Sep 5, 2015
    I want to add conditions for morning and afternoon.
    How would I do this without incurring a Syntax Error in Game_Map?

    Code:
    isNight?

    I'm sure you can figure how to make it check if its morning lol
     
    15
    Posts
    13
    Years
    • Seen Aug 9, 2016
    Code:
    isNight?

    I'm sure you can figure how to make it check if its morning lol

    I know, but the problem is not that simple.
    I found the checks for morning and afternoon and attempted:
    Code:
      def autoplayAsCue
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
          else
        if PBDayNight.isMorning?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
            pbCueBGM(@map.bgm.name+"m",1.0,@map.bgm.volume,@map.bgm.pitch)
          else
            pbCueBGM(@map.bgm,1.0)
          end
        end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end

    I got a Syntax Error on Line 480 where the Class Game_Map is defined.
    also tried else if statement. same result
    I'm a bit rusty, but I can't find out why this doesn't work.
     
    84
    Posts
    10
    Years
    • Seen Jun 11, 2022
    ^Try including 'pbCueBGM(@map.bgm,1.0)' after both music cues (at the moment it's only after the second 'morning' conditional). Otherwise, or, in addition to this, try changing that second 'if' to 'elsif'.
     
    15
    Posts
    13
    Years
    • Seen Aug 9, 2016
    ^Try including 'pbCueBGM(@map.bgm,1.0)' after both music cues (at the moment it's only after the second 'morning' conditional). Otherwise, or, in addition to this, try changing that second 'if' to 'elsif'.

    I tried this and got a similar error.
    why do you think this is?
     
    15
    Posts
    13
    Years
    • Seen Aug 9, 2016
    Alright,
    After a long series of trial and error, I managed to develop a far more expanded and specific code that will allow for Morning and Afternoon conditions to be checked.
    Every other method I used resulted in a Syntax Error, but this one should be totally safe for all versions of Essentials.

    Simply replace the "def autoplayAsCue" and "def autoplay" sections in Game_Map with the following code:
    Code:
      #-----------------------------------------------------------------------------
      # * Autoplays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplayAsCue
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
          end
          if PBDayNight.isAfternoon?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
            pbCueBGM(@map.bgm.name+"a",1.0,@map.bgm.volume,@map.bgm.pitch)
          end
          if PBDayNight.isMorning?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
            pbCueBGM(@map.bgm.name+"m",1.0,@map.bgm.volume,@map.bgm.pitch)
          end
          
          if PBDayNight.isNight?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm,1.0)
          end
          if PBDayNight.isAfternoon?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
            pbCueBGM(@map.bgm,1.0)
          end
          if PBDayNight.isMorning?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
            pbCueBGM(@map.bgm,1.0)
          end
          if PBDayNight.isDay?(pbGetTimeNow) &&
                !PBDayNight.isMorning?(pbGetTimeNow) &&
                !PBDayNight.isAfternoon?(pbGetTimeNow)
            pbCueBGM(@map.bgm,1.0)
          end
          end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end
      #-----------------------------------------------------------------------------
      # * Plays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplay
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
                pbBGMPlay(@map.bgm.name+"n",@map.bgm.volume,@map.bgm.pitch)
          end
          if PBDayNight.isMorning?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
                pbBGMPlay(@map.bgm.name+"m",@map.bgm.volume,@map.bgm.pitch)
          end
          if PBDayNight.isAfternoon?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
                pbBGMPlay(@map.bgm.name+"a",@map.bgm.volume,@map.bgm.pitch)
          end
              
          if PBDayNight.isAfternoon?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
            pbBGMPlay(@map.bgm)
          end
          if PBDayNight.isMorning?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
            pbBGMPlay(@map.bgm)
          end
          if PBDayNight.isNight?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbBGMPlay(@map.bgm)
          end
          if PBDayNight.isDay?(pbGetTimeNow) &&
                !PBDayNight.isMorning?(pbGetTimeNow) &&
                !PBDayNight.isAfternoon?(pbGetTimeNow)
            pbBGMPlay(@map.bgm)
          end
          end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end
    Simply add "a" or "m" to the end of your audio filename for Afternoon and Morning respectively, as with "n" for Night.


    Happy Coding!
     
    824
    Posts
    8
    Years
  • Alright,
    After a long series of trial and error, I managed to develop a far more expanded and specific code that will allow for Morning and Afternoon conditions to be checked.
    Every other method I used resulted in a Syntax Error, but this one should be totally safe for all versions of Essentials.

    Simply replace the "def autoplayAsCue" and "def autoplay" sections in Game_Map with the following code:
    Code:
      #-----------------------------------------------------------------------------
      # * Autoplays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplayAsCue
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
          elsif PBDayNight.isAfternoon?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
            pbCueBGM(@map.bgm.name+"a",1.0,@map.bgm.volume,@map.bgm.pitch)
          elsif PBDayNight.isMorning?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
            pbCueBGM(@map.bgm.name+"m",1.0,@map.bgm.volume,@map.bgm.pitch)
          else
            pbCueBGM(@map.bgm,1.0)
          end
        end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end
      #-----------------------------------------------------------------------------
      # * Plays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplay
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
                pbBGMPlay(@map.bgm.name+"n",@map.bgm.volume,@map.bgm.pitch)
          elsif PBDayNight.isMorning?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
                pbBGMPlay(@map.bgm.name+"m",@map.bgm.volume,@map.bgm.pitch)
          elsif PBDayNight.isAfternoon?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
                pbBGMPlay(@map.bgm.name+"a",@map.bgm.volume,@map.bgm.pitch)
          else
            pbBGMPlay(@map.bgm)
          end
        end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end
    Simply add "a" or "m" to the end of your audio filename for Afternoon and Morning respectively, as with "n" for Night.


    Happy Coding!

    I replaced the long series of "if/end"s with one "if/elsif/elsif/.../else/end" string. This may have been one of the methods you tried that threw up a syntax error.

    @Minokun - PokeCommunity breaks code. Be sure to click "show printable version" before copying either my or Khari's code.
     
    15
    Posts
    13
    Years
    • Seen Aug 9, 2016
    I replaced the long series of "if/end"s with one "if/elsif/elsif/.../else/end" string. This may have been one of the methods you tried that threw up a syntax error.

    @Minokun - PokeCommunity breaks code. Be sure to click "show printable version" before copying either my or Khari's code.

    AND THERE WAS THE PROBLEM!

    I had made the mistake of entering "else if" instead of "elsif", which works entirely different in Ruby than many other languages.
    Thank you kind sir and good work!
     
    824
    Posts
    8
    Years
  • AND THERE WAS THE PROBLEM!

    I had made the mistake of entering "else if" instead of "elsif", which works entirely different in Ruby than many other languages.
    Thank you kind sir and good work!

    You're welcome.

    Don't worry, I came from a coding language where "elseif" was spelled with another E, so it took me a while to catch on as well.
     
    Back
    Top