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:

 

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

 

 

 

should be changed to:

 

Event OnTriggerLeave(ObjectReference akActionRef)
    If akActionRef == Game.GetPlayer()
        kDefObjMan.SetForm("BTMS", CurrentCombatMusicType) ;set battle music back to default vanilla type
        CurrentCombatMusicType = None
    Endif
EndEvent

 

a slightly changed script as follow:

; https://forums.nexusmods.com/index.php?/topic/10180243-script-to-temporarily-change-combat-music-does-one-exist/

  DefaultObjectManager Property kDefObjMan auto Hidden

  MusicType Property NewCombatMusic auto
  Form      Property CurrentCombatMusicType auto Hidden


; -- EVENTs --

; https://www.creationkit.com/index.php?title=DefaultObjectManager_Script

EVENT OnInit()
    Debug.Trace(" OnInit() - has been reached for " +self)
ENDEVENT


EVENT OnTriggerEnter(ObjectReference triggerRef)
    IF (triggerRef == Game.GetPlayer() as ObjectReference)
        gotoState("Waiting")        ; ### STATE ###
        myF_Action(1)
    ENDIF
ENDEVENT


;===========================
state Waiting
;============
    EVENT OnTriggerEnter(ObjectReference triggerRef)
    ENDEVENT

    EVENT OnTriggerLeave(ObjectReference triggerRef)
        IF (triggerRef == Game.GetPlayer() as ObjectReference)
            gotoState("")            ; ### STATE ###
            myF_Action(0)
        ENDIF
    ENDEVENT

    EVENT OnCellDetach()
        IF Game.GetPlayer().IsInCombat()
            RETURN    ; - STOP -    do nothing, if player has combat action
        ENDIF
;        ----------------------
        gotoState("")
        myF_Action(0)
    ENDEVENT
;=======
endState


; -- FUNCTION --

;----------------------
FUNCTION myF_StoreDOM()
;---------------------- EDITED because of compiler error
    kDefObjMan = Game.GetForm(0x00000031) as DefaultObjectManager     ; fill hidden property with DefaultObjectManager from skyrim.esm
ENDFUNCTION


;-------------------------
FUNCTION myF_Action(Int i)
;-------------------------
    IF ( kDefObjMan )
    ELSE
        myF_StoreDOM()
    ENDIF

IF (SKSE.GetVersion() > 0)
ELSE
    Debug.Trace(self + " SKSE is missing!")            ; getform(), setform() required SKSE
    RETURN    ; - STOP -
ENDIF
;--------------------- "BTMS" - Battle Music
    IF (i == 1)
        CurrentCombatMusicType = kDefObjMan.GetForm("BTMS")          ; save current Battle Music
        kDefObjMan.SetForm("BTMS", NewCombatMusic as Form)           ; set battle music to MyCombatMusic
    ELSE
        kDefObjMan.SetForm("BTMS", CurrentCombatMusicType)           ; set battle music back to "what it was before"
        CurrentCombatMusicType = None                                ; clear hidden property
    ENDIF
ENDEVENT

 

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

; https://forums.nexusmods.com/index.php?/topic/10180243-script-to-temporarily-change-combat-music-does-one-exist/

  DefaultObjectManager PROPERTY ps auto Hidden        ; pointer to script

  MusicType PROPERTY myBattleMusic auto
  Form      PROPERTY CurrentBM     auto Hidden


; -- EVENTs --

; https://www.creationkit.com/index.php?title=DefaultObjectManager_Script

EVENT OnInit()
    Debug.Trace(" OnInit() - has been reached for " +self)
ENDEVENT


EVENT OnCellAttach()
    gotoState("Waiting")        ; ### STATE ###
    myF_Action(1)
ENDEVENT


;===========================
state Waiting
;============
    EVENT OnCellAttach()
    ENDEVENT

    EVENT OnCellDetach()
        actor player = Game.GetPlayer()
        WHILE player.IsInCombat()
            Utility.Wait(1.0)
        ENDWHILE
    
        gotoState("")            ; ### STATE ###
        myF_Action(0)
    ENDEVENT
;=======
endState


; -- FUNCTIONs -- 2

;----------------------
FUNCTION myF_StoreDOM()
;----------------------
    ps = Game.GetForm(0x00000031) as DefaultObjectManager     ; fill hidden property with DefaultObjectManager from skyrim.esm
ENDFUNCTION


;-------------------------
FUNCTION myF_Action(Int i)
;-------------------------
    IF ( ps )
    ELSE
        myF_StoreDOM()
    ENDIF

IF (SKSE.GetVersion() > 0)
ELSE
    Debug.Trace(self + " SKSE is missing!")         ; getform(), setform() required SKSE
    RETURN    ; - STOP -
ENDIF
;--------------------- "BTMS" - Battle Music
    IF (i == 1)
        CurrentBM = ps.GetForm("BTMS")              ; save current Battle Music
        ps.SetForm("BTMS", myBattleMusic as Form)   ; set battle music to MyCombatMusic
    ELSE
        ps.SetForm("BTMS", CurrentBM)               ; set battle music back to "what it was before"
        CurrentBM = None                            ; clear hidden property
    ENDIF
ENDEVENT

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:

 

 

 

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 
    RegisterForKey(42) ;left shift
EndEvent 

Event OnKeyDown(Int keyCode) 
    If kDefObjMan.GetForm("BTMS") == MyCombatMusic 
        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 
    Else 
        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

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:

 

 

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 OnLoad() 
    Debug.Notification("Setting custom combat music")
        
    CurrentCombatMusicType = kDefObjMan.GetForm("BTMS") ;Save current Battle Music 
    kDefObjMan.Setform("BTMS", MyCombatMusic) ;set battle music to MyCombatMusic
EndEvent 

Event OnUnload() 
    Debug.Notification("Setting combat music back to vanilla.")
    kDefObjMan.SetForm("BTMS", CurrentCombatMusicType) ;set battle music back to what it was before 
EndEvent

 

 

 

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...