Dynamic Battle Music for Preemptive/ Surprise battle

I'm looking for a script that allows you to choose a music for preemptive/ surprise battle.
Preemptive/ Surprise battle has their own music. Filepath for music file can be located inside project folder > Audio > BGM

Default setting example-
Preemptive = 'Preemptive1.ogg'
Surprise = 'Surprise1.ogg'

If lefted blank, Battle music from database will be used.

Optional feature:
Settings for # switch to alternate music.

If switch X is on, this setting will be used for battle music.

Example-
Battle = 'Battle2.ogg'
Preemptive = 'Preemptive2.ogg'
Surprise = 'Surprise2.ogg'

If lefted blank, music from default setting will be used.
there is an alternative to your idea.

Tsukihime has a script for running a common event before all battles, including random battles.
I don't remember the exact name on himeworks.com, you'll have to look for it.

but with that script you can write a common event that handles all changes before the battle is launched.
I looked through himeworks list of scripts and found a possible script.
https://himeworks.com/rmvxa-scripts/

Seems specifically for whenever a skill or item is used, on the map or in a battle. Similar to Effect: Common Event with a use of a tag
https://himeworks.com/2013/04/common-event-variables/

2 other scripts for Common Event Arguments and Common Event Triggers are not available.

Appreciate alternatives though
Ruby:
#===============================================================================
# Title: Preemptive Surprise BGM
# Author: Roninator2
# Date: Nov 12, 2021
#-------------------------------------------------------------------------------   
# ** Terms of Use
# * Free to use in all projects
#-------------------------------------------------------------------------------
# ** Description
#
# This script allows you to assign a BGM and/or Victory ME to a troop.
# The BGM/ME will be played whenever that troop is encountered instead of the
# default one.
#
#-------------------------------------------------------------------------------
# ** Instructions
#
#  Set Music and volume, pitch to your preference
#   
#===============================================================================

module R2_battle_switch_bgm
  # switch BGM
  SWITCH_BGM = 1
  Switch_Title = "Field1"
  Switch_Volume = 100
  Switch_Pitch = 100
  # @preemptive bgm
  Pre_Title = "Field2"
  Pre_Volume = 100
  Pre_Pitch = 100
  # @surprise bgm
  Sur_Title = "Field3"
  Sur_Volume = 100
  Sur_Pitch = 100
end

module BattleManager
 
  def self.play_battle_bgm
    if $game_switches[R2_battle_switch_bgm::SWITCH_BGM] == true
      bgm = RPG::BGM.new(R2_battle_switch_bgm::Switch_Title,
      R2_battle_switch_bgm::Switch_Volume, R2_battle_switch_bgm::Switch_Pitch)
      bgm.play
    elsif @preemptive
      bgm = RPG::BGM.new(R2_battle_switch_bgm::Pre_Title,
      R2_battle_switch_bgm::Pre_Volume, R2_battle_switch_bgm::Pre_Pitch)
      bgm.play
    elsif @surprise
      bgm = RPG::BGM.new(R2_battle_switch_bgm::Sur_Title,
      R2_battle_switch_bgm::Sur_Volume, R2_battle_switch_bgm::Sur_Pitch)
      bgm.play
    else
      $game_system.battle_bgm.play
    end
      RPG::BGS.stop
  end
end
Script tested-
Battle BGM does change along with volume and pitch when switch 1 is on. However preemptive and surprise plays Field1 with same volume and pitch like Switch_Title.
Do you have the switch turned on? if the switch is on it will always play Switch_Title
I tried with switch 1 off. Battle music changed to Field3 when surprised and for preemptive is Field2.

Switch works as intended. I was thinking of the opposite. Your version of the script is exactly what I'm looking for. Thank you!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/dynamic-battle-music-for-preemptive-surprise-battle.142076/