Jump to content

Script to "temporarily" change combat music, does one exist?


Recommended Posts

Looking for a script to use custom combat music for either a single encounter, location area, or cell without replacing vanilla. Curious if anyone has ever worked on or seen something like this?

 

 

Link to comment
Share on other sites

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

Hey, I know I said before I didn't know how, but I figured it out. I was looking to solve something else and I stumbled upon the DefaultObjectManager script from SKSE.

 

What you can do is use a triggerBox to change combat music temporarily.

MusicType Property MyCombatMusic Auto 
MusicType Property MUSCombat Auto ;vanilla combat music
Form Property CurrentCombatMusicType Auto Hidden 
DefaultObjectManager Property kDefObjMan Auto Hidden

Event OnInit()
    kDefObjMan = Game.GetFormFromFile(0x00000031, "Skyrim.esm") as DefaultObjectManager ;get DefaultObjectManager form from skyrim.esm 
EndEvent 

Event OnTriggerEnter(ObjectReference akActionRef)
    If akActionRef == Game.GetPlayer()
        CurrentCombatMusicType = kDefObjMan.GetForm("BTMS") ;Save current Battle Music 
        kDefObjMan.Setform("BTMS", MyCombatMusic) ;set battle music to MyCombatMusic
    Endif
EndEvent 

Event OnTriggerLeave(ObjectReference akActionRef)
    If akActionRef == Game.GetPlayer()
        If CurrentCombatMusicType ;if current battle music type was found
            kDefObjMan.SetForm("BTMS", CurrentCombatMusicType) ;set battle music back to what it was before 
        Else 
            kDefObjMan.SetForm("BTMS", CurrentCombatMusicType) ;set battle music back to default vanilla type
        Endif 
    Endif
EndEvent

To see what other Default Objects you can change, go here: https://www.creationkit.com/index.php?title=DefaultObjectManager_Script

 

To see what the vanilla objects are, in the Creation Kit, under the GamePlay tab select Default Objects.

Link to comment
Share on other sites

I've said it before and I'll say again... DYLBILL YOU DA MAN!!!!

 

Simply awesome as always many thanks man!

 

Will be testing this promptly.

Link to comment
Share on other sites

Ok first run with it late last night, it wasn't immediate there was a huge delay but it did work once. But thereafter on subsequent entering and leaving of the trigger, it wouldn't fire off again, weird?

 

Just to be sure for the script header it is extending ObjectReference correct?

Edited by Laerithryn
Link to comment
Share on other sites

Yes, and also make sure that your trigger box is big enough to encompass the entire area you want to have custom combat music. I did some testing myself and found that if you're already in combat, the music won't change until you leave and then enter combat again. Also, make sure your custom combat MusicType has a fade duration, or it will just keep playing even after you've left combat.

 

To make sure it's setting combat music at the correct times, you can add some debug notifications:

 

MusicType Property MyCombatMusic Auto 
MusicType Property MUSCombat Auto ;vanilla combat music
Form Property CurrentCombatMusicType Auto Hidden 
DefaultObjectManager Property kDefObjMan Auto Hidden

Event OnInit()
    kDefObjMan = Game.GetFormFromFile(0x00000031, "Skyrim.esm") as DefaultObjectManager ;get DefaultObjectManager form from skyrim.esm 
EndEvent 

Event OnTriggerEnter(ObjectReference akActionRef)
    If akActionRef == Game.GetPlayer()
        Debug.Notification("Setting custom combat music")
        
        CurrentCombatMusicType = kDefObjMan.GetForm("BTMS") ;Save current Battle Music 
        kDefObjMan.Setform("BTMS", MyCombatMusic) ;set battle music to MyCombatMusic
    Endif
EndEvent 

Event OnTriggerLeave(ObjectReference akActionRef)
    If akActionRef == Game.GetPlayer()
        Debug.Notification("Setting combat music back to vanilla.")
        
        If CurrentCombatMusicType ;if current battle music type was found
            kDefObjMan.SetForm("BTMS", CurrentCombatMusicType) ;set battle music back to what it was before 
        Else 
            kDefObjMan.SetForm("BTMS", CurrentCombatMusicType) ;set battle music back to default vanilla type
        Endif 
    Endif
EndEvent
Link to comment
Share on other sites

In dylbill's sample script, the code to restore is a bit strange.

 

his code:

  Reveal hidden contents

 

 

should be changed to:

  Reveal hidden contents

 

a slightly changed script as follow:

  Reveal hidden contents

 

another approach without trigger action (added: 27 June 2021)

  Reveal hidden contents

Edited by ReDragon2013
Link to comment
Share on other sites

@ReDragon2013. I added that as a failsafe in case CurrentCombatMusicType wasn't found (it's none). I suppose you're right though, if another script had previously set the combat music to None it should be set to None when leaving the triggerbox.

Link to comment
Share on other sites

@ReDragon2013. Much appreciate the response. On your last "slightly change script" I get the following errors trying to compile.


Starting 1 compile threads for 1 files...

Compiling "MUSCombatToggle2"...

C:\Games\Steam\steamapps\common\Skyrim Special Edition\Data\Source\Scripts\temp\MUSCombatToggle2.psc(58,22): GetFormFrom is not a function or does not exist

C:\Games\Steam\steamapps\common\Skyrim Special Edition\Data\Source\Scripts\temp\MUSCombatToggle2.psc(58,22): cannot call the member function GetFormFrom alone or on a type, must call it on a variable

C:\Games\Steam\steamapps\common\Skyrim Special Edition\Data\Source\Scripts\temp\MUSCombatToggle2.psc(58,46): cannot cast a none to a defaultobjectmanager, types are incompatible

No output generated for MUSCombatToggle2, compilation failed.


Batch compile of 1 files finished. 0 succeeded, 1 failed.

Failed on MUSCombatToggle2


-------------


I'm can't get any of these to work in practice unfortunately. Last night Dylbill's original script worked once only but there after nothing entering or leaving the trigger box.


-------------


Question: If a trigger box is the same size as the room it is applied to; and a COC marker is placed within the trigger, does using COC into the room count as entering the trigger? Or does the player have to enter by tripping it as normal?

Edited by Laerithryn
Link to comment
Share on other sites

"placed within the trigger, does using COC into the room count as entering the trigger? Or does the player have to enter by tripping it as normal?"

 

I'm actually not sure about this, which is why I recommended to add the debug.notifications() so you can see when it's setting the music.

 

To test I actually used a hotkey, which is how I test most things when I'm working on them:

 

 

  Reveal hidden contents

Another option, is if it's an interior cell you're wanting to set the music for, you can put a script on a normal objectreference you have in the cell, and use the Load and Unload events:

 

  Reveal hidden contents

 

 

Also, make sure you're testing on a save that hasn't "seen" your object yet, or the OnInit() event won't fire because the object will have already been loaded in your game.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...