I have a BGM that plays when my player is detected, but how do I revert to normal BGM?

Sorry for the lenghty title, but I didn't know how to explain this in shorter ways to make a title...


Anyways, hello!

So, I'm making an MGS-style infiltration moment in my game, and I'm using Yanfly's Event chaser. This allows me to use a common event, that I use to change the ongoing BGM to a "You should run!" one.

Now, that's all working fine, but... How do I revert back to the normal BGM, once the enemy isn't chasing anymore?

I can manage to restore it back when the enemy is defeated, just by using the "replay saved BGM" after the battle event just fine, just not when the enemy goes back to it's original spot, still alive...

tldr: I need the BGM to go back to normal when the enemy returns to it's original spot after losing the chased player.

Thanks for the help!
Open the event chase plugin with notepad and put this:

$gameSystem.replayBgm();

in there somewhere. I tried putting it after this:

Game_Event.prototype.endEventChase = function() {
this._chasePlayer = false;

and it worked, but you can also try other spots, if you want it to start in some other way.


EDIT: You need to save the current BGM at the chase common event, before playing the chase music, for that to work.
You could make a parallel process that checks the event's region and if it matches their starting position (you need to apply a region on their starting position/patrol area of course), then flip the bgm, i would make it so this parallel triggers on a switch, and this switch turns on when the common event for detection triggers to save unnecesary processing.

Detect common event: switch X on

Parallel:
Check chasing event region
If event region=starting region
Change bgm
Flip switch X off
@rpgLord69 That sorta does the trick, except the music reverts back to normal as soon as the player gets out of sight, and not when the NPC reaches his original spot.

@BK-tdm How exactly do I set up the parallel event? With variables? I can't seem to find what I'm supposed to use for the "check chasing event region" part?
Sorry im nowhere near a RM right now to properly set it up so i just gave the overall idea ill get back to this later today 😅
@rpgLord69 That sorta does the trick, except the music reverts back to normal as soon as the player gets out of sight, and not when the NPC reaches his original spot.

Okay, put it at the very end:

if (sx === 0 && sy === 0) {
$gameSystem.replayBgm();
this._returnPhase = false;
this._returnFrames = 0;
this._direction = this._startLocationDir;

EDIT: Just to clarify, put the bolded line in that spot of code that already exists at the end of the plugin.
Okay, put it at the very end:

if (sx === 0 && sy === 0) {
$gameSystem.replayBgm();
this._returnPhase = false;
this._returnFrames = 0;
this._direction = this._startLocationDir;

EDIT: Just to clarify, put the bolded line in that spot of code that already exists at the end of the plugin.

Works like a charm! Thanks a lot 🙂

Original thread: https://forums.rpgmakerweb.com/threads/i-have-a-bgm-that-plays-when-my-player-is-detected-but-how-do-i-revert-to-normal-bgm.154885/