Is there an elegant way to automatically change battle music depending on area?

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
256
Reaction score
94
First Language
English
Primarily Uses
RMMZ
Kinda like how it works in Kingdom Hearts. I thought that a way would be to assign specific battle music to troops, but that only changes it after an annoying beginning. Any ideas? Would a common event running parallel work?
 

Weremole

Veteran
Veteran
Joined
Jan 22, 2016
Messages
346
Reaction score
312
First Language
Swedish
Primarily Uses
Depends on how you define areas. If it's a specific place, then just change the battle music in the teleport event. If its on the same map then check what region or terrain tag the player is standing on and change it with a paralell process event.
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
256
Reaction score
94
First Language
English
Primarily Uses
RMMZ
It would be with "places" yes, but the idea about regions is quite interesting indeed.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
37,030
Reaction score
10,027
First Language
German
Primarily Uses
RMMV
it also depends on what kind of battles you're using.
for evented battles this is as easy as changing the battlemusic before the battle processing command.
there is only a problem when using random battles as those have no event commands before battle processing.

if you are using random encounters, then (as said above) it depends completely on how you define your "places". there are quite a number of different options depending on how you define that, so you might give some more specifications if the answers above are not enough.
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
256
Reaction score
94
First Language
English
Primarily Uses
RMMZ
It would be for random battles, not event battles, yes.
Place = one area and its sub-areas
 

RianQuenlin

Veteran
Veteran
Joined
Jul 28, 2022
Messages
100
Reaction score
68
First Language
English
Primarily Uses
N/A
.
 
Last edited:

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
256
Reaction score
94
First Language
English
Primarily Uses
RMMZ
Alternatively, you can run a common event that checks the map ID and changes it
That was what I thought originally, but thought it was somewhat clunky?
 

RianQuenlin

Veteran
Veteran
Joined
Jul 28, 2022
Messages
100
Reaction score
68
First Language
English
Primarily Uses
N/A
.
 
Last edited:

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
615
Reaction score
609
First Language
English
Primarily Uses
RMMZ
Paste this script into a new .js file and add it to the project through the plugin manager:

JavaScript:
const Art_Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
    Art_Game_Map_setup.call(this, mapId);
    const defBattleBgm = $dataSystem.battleBgm;
    if ($dataMap.meta.battleBGM) {
        $gameSystem.setBattleBgm({name: $dataMap.meta.battleBGM.trim(), pitch: defBattleBgm.pitch, volume: defBattleBgm.volume});
    } else {
        $gameSystem.setBattleBgm(defBattleBgm);
    }
};

Then you can put <battleBGM: FileName> in the note box of your map, and it will play the specified BGM for any battles on that map. Just replace FileName with the actual name of the audio file (without the extension). So if the file is Battle1.ogg, then the note tag would look like:
Code:
<battleBGM: Battle1>

For any map that doesn't have a note tag, it will use the default battle BGM (meaning whichever one you defined in the System tab in your database).
 
Last edited:

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
256
Reaction score
94
First Language
English
Primarily Uses
RMMZ
This is a very elegant solution, thank you very much. But this overrides event battles, yes= unless I put them in a different map!
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
615
Reaction score
609
First Language
English
Primarily Uses
RMMZ
This is a very elegant solution, thank you very much. But this overrides event battles, yes= unless I put them in a different map!
It won't override event battles. If you want the event battle to have different music, just use the "Change Battle BGM" event command (Tab 3, under "System Settings") right before you use the Battle Processing event command. I.e.:

Code:
◆Change Battle BGM:Battle4 (90, 100, 0)
◆Battle Processing:Goblin*2
:If Win
  ◆
:If Escape
  ◆
:End

That will keep it changed, until the next time you change maps. If you want the BGM change to only apply to that one battle, then just set it back right after the Battle Processing command. I.e.:

Code:
◆Change Battle BGM:Battle4 (90, 100, 0)
◆Battle Processing:Goblin*2
:If Win
  ◆
:If Escape
  ◆
:End
◆Change Battle BGM:Battle1 (90, 100, 0)
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
256
Reaction score
94
First Language
English
Primarily Uses
RMMZ
Why thank you so much. I'll try it as soon as I can!
 

Dark_Ansem

Veteran
Veteran
Joined
Jun 16, 2020
Messages
256
Reaction score
94
First Language
English
Primarily Uses
RMMZ
It won't override event battles. If you want the event battle to have different music, just use the "Change Battle BGM" event command (Tab 3, under "System Settings") right before you use the Battle Processing event command. I.e.:

Code:
◆Change Battle BGM:Battle4 (90, 100, 0)
◆Battle Processing:Goblin*2
:If Win
  ◆
:If Escape
  ◆
:End

That will keep it changed, until the next time you change maps. If you want the BGM change to only apply to that one battle, then just set it back right after the Battle Processing command. I.e.:

Code:
◆Change Battle BGM:Battle4 (90, 100, 0)
◆Battle Processing:Goblin*2
:If Win
  ◆
:If Escape
  ◆
:End
◆Change Battle BGM:Battle1 (90, 100, 0)
So, I'm sorry to ask again, but I tried to make a small change to add a condition for certain maps to use the map music for battle music but I failed. Could you please help?
 

Latest Threads

Latest Profile Posts

M42S7Us.gif

It's the little things. Lengthened the time the bar fades in and out to be a bit more comfortable.
3 days until release!
Well, with one problem (the hurricane) over with, we now have another problem. My dad and stepmom both tested positive for COVID-19 and I'm unable to visit them anytime soon. Meanwhile, I've just posted a new video on my YouTube.
I am back...from the land of the dead!

Forum statistics

Threads
125,730
Messages
1,173,084
Members
164,872
Latest member
chorustrilogy
Top