Stop playing map music after a battle is completed?

Here's the original topic I made.

https://forums.rpgmakerweb.com/index.php?threads/boss-battle-music-start-in-the-cutscene.109536/

Basically, I would like a way to stop music from playing after a specific battle is completed.

The reason I need a plugin for this is because I want the boss music to start playing during the cutscene before the battle and seamlessly transition into the same music during the battle. I can do this, but the problem is after the battle is completed, the results screen (that shows the XP, money, and items you get) continues to play the music because that's what was set before entering the battle. Of course I can get it to end instantly after the results screen, but it'll still play during the results screen.

If you know of a way to get that fixed with events, please let me know, but in my above topic I was told that it needs a plugin.

Thanks in advance! I hope this request is easy.
Give this a try. Either create a new file called "StopMapBgm.js" and save everything in the code block as the contents of the file, or download it from here.

Make sure you name it exactly "StopMapBgm.js" if you create it yourself. The Plugin Parameters won't be properly read if you name it something else. The order you import it should not matter.

There's one Plugin Parameter to setup, which is just to specify which game switch you would like to use to indicate that the current Map's BGM should not play after battle. By default, it's Switch 20, so if Switch 20 is on, then when a battle ends, the music that was playing on the Map will not continue to play.

Code:
/*:
* @plugindesc Allows a user to specify a switch to use to indicate whether a Map's BGM should
* continue to play after battle end. If the switch is ON, it will not play.
* @author Zevia
*
* @help Specify a switch in the setup, then whenever that switch is ON, the BGM on the
* Map will stop after the battle is over. If a victory ME is enabled, it will stop the Map
* music from playing after the victory ME. If a victory ME is not enabled, it will stop
* the Map music from playing as soon as the battle processes its end.
*
* @param switchNumber
* @text Stop Map BGM Switch
* @type switch
* @default 20
*/

(function(module) {
    'use strict';

    module.Zevia = module.Zevia || {};
    var StopMapBgm = module.Zevia.stopMapBgm = {};

    var stopSwitch = parseInt(PluginManager.parameters('StopMapBgm').switchNumber);
    if (isNaN(stopSwitch)) {
        throw new Error('The switch specified needs to be an Integer, please check the Plugin settings for StopMapBgm');
    }

    StopMapBgm.replayBattleBgsAndBgm = BattleManager.replayBgmAndBgs;
    BattleManager.replayBgmAndBgs = function() {
        if ($gameSwitches._data[stopSwitch]) {
            BattleManager._mapBgm = null;
        }
        StopMapBgm.replayBattleBgsAndBgm.call(BattleManager);
    };
})(window);

Let me know if it works for your needs.
Thanks for making this for me! I tested it out and it works great!

Original thread: https://forums.rpgmakerweb.com/threads/stop-playing-map-music-after-a-battle-is-completed.109541/