This can be done with events. I'm not sure you need to make mods to the script.
I know for certain that there is code that will check the player's (or an event's) x, y coordinates. You can compare this to the latter and change the music when your characters reaches so many panels from your enemy.