Save-Point
BGM No Loop - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: HiddenChest (RGSS1-3) Engine (https://www.save-point.org/forum-118.html)
+---- Thread: BGM No Loop (/thread-8961.html)



BGM No Loop - kyonides - 06-06-2024

BGM No Loop

HiddenChest Exclusive!
XP Related

by Kyonides

Introduction

This is a simple scriplet that will let RMXP users play one BGM after another based on which map ID's are included in the MAP_BGM array.

There still is one important detail you must know: Audio.bgm_loop is set to true, meaning that all the other maps will keep playing the same old song. Metalhead Rapper 

Warning

You need to be using HiddenChest version 1.1.81 or later!

Script for RMXP Editor
Code:
# * BGM No Loop XP * #
#   Scripter : Kyonides Arkanthes
#   2024-06-13

# This scriptlet allows you to prevent the game from playing the same old song
# over and over again. Now you can define a list of BGMs for specific maps!

module BgmNoLoop
  WAIT = 20
  VOLUME = 60
  MAP_BGM = {}
  MAP_BGM[1] = ["015-Theme04", "017-Theme06"]
end

class Game_Map
  alias :kyon_bgm_no_loop_gm_map_setup :setup
  def setup(map_id)
    check_bgm_loop(map_id)
    kyon_bgm_no_loop_gm_map_setup(map_id)
  end

  def check_bgm_loop(map_id)
    Audio.bgm_loop = !BgmNoLoop::MAP_BGM.has_key?(map_id)
    puts "Check Loop in Map ##{map_id}: " + Audio.bgm_loop.to_s
  end

  def map_bgm
    @map.bgm
  end

  def find_bgms
    bgm = @map.bgm
    $game_system.bgm_volume = bgm.volume
    bgms = []
    bgms << bgm unless bgm.name.empty?
    bgms + BgmNoLoop::MAP_BGM[@map_id]
  end
end

class Game_System
  alias :kyon_bgm_no_loop_gm_sys_init :initialize
  alias :kyon_bgm_no_loop_gm_sys_up :update
  def initialize
    kyon_bgm_no_loop_gm_sys_init
    reset_bgm_timer
    reset_bgm_volume
    @bgm_index = 0
  end

  def reset_bgm_timer
    @bgm_timer = BgmNoLoop::WAIT
  end

  def reset_bgm_volume
    @bgm_volume ||= BgmNoLoop::VOLUME
  end

  def update
    kyon_bgm_no_loop_gm_sys_up
    return if $game_temp.in_battle or Audio.bgm_playing?
    return if Audio.bgm_loop
    if @bgm_timer > 0
      @bgm_timer -= 1
      return
    end
    reset_bgm_timer
    bgms = $game_map.find_bgms
    @bgm_index ||= 0
    @bgm_index = (@bgm_index + 1) % bgms.size
    bgm = bgms[@bgm_index]
    bgm = RPG::AudioFile.new(bgm) if bgm.is_a?(String)
    bgm_play(bgm) if bgm != nil
  end

  def bgm_play(bgm)
    reset_bgm_volume
    @playing_bgm = bgm
    if bgm != nil and bgm.name != ""
      Audio.bgm_play("Audio/BGM/" + bgm.name, @bgm_volume, bgm.pitch)
    else
      Audio.bgm_stop
    end
    Graphics.frame_reset
  end
  attr_accessor :bgm_volume
end

Terms & Conditions

Free for any kind of game running on the HiddenChest engine. [Image: wink.gif]
Due credit is mandatory.
Don't post the contents of this topic anywhere else!
You better paste a link to this thread and make them come here instead.
That's it! [Image: tongue.gif]


RE: BGM No Loop - Mel - 06-06-2024

Are the themes always playing in order or can you play them randomly? So that it doesnt always start with the same old first track of the array when you enter the map :P


RE: BGM No Loop - kyonides - 06-06-2024

Interesting Update

After getting the same request from 2 different individuals, namely 2 people whose avatars are connected to the night, I decided to let my script play the songs randomly.

Really, I didn't feel Indifferent the need to do that but I guess Thinking that I had no other choice but to implement it at once.