dylbill Posted June 27, 2021 Share Posted June 27, 2021 Hmmm, not sure. Try doing the Add() and Remove() method then. Link to comment Share on other sites More sharing options...
Laerithryn Posted June 27, 2021 Author Share Posted June 27, 2021 (edited) Will do, it'll be on tomorrow's agenda for me as I'm pretty much tapped out for the day. Don't want it to go with out being said, as always thank you Dylbill. OBTW, found this default script in the CK a while back, pretty sure you've seen it before. scriptName defaultAddMusicSCRIPT extends ObjectReference {plays music when player enters trigger} MusicType property myMusic auto {Music to play when player enters trigger} Auto STATE Listening EVENT onTriggerEnter (objectReference triggerRef) Actor actorRef = triggerRef as Actor if (actorRef == game.GetPlayer()) gotoState ("done") myMusic.Add() endif endEVENT endState STATE done ; do nothing endSTATE I've tested it and found that it's pretty reliable for putting a Music Type in place where the cell is set to default. Problem is you can't use it twice in the same cell to override itself with another choice. Heck if you could I wouldn't be having a hard time of it. Edited June 27, 2021 by Laerithryn Link to comment Share on other sites More sharing options...
dylbill Posted June 28, 2021 Share Posted June 28, 2021 I think maybe that script isn't working cause it never calls Remove() on the musictype. Link to comment Share on other sites More sharing options...
Laerithryn Posted June 29, 2021 Author Share Posted June 29, 2021 (edited) @Dylbill on the subject . . . Hmmm, because that's a pretty bad bug, I would maybe try maxaturo's idea of using Add() and Remove(). You have to detect when the player enters combat, and to do this I would make a new spell ability that has the condition IsInCombat == 1 and add it to the player when they enter the cell. This is because the event OnCombatStateChanged doesn't work for the player. triggerbox script: Actor Property PlayerRef Auto Spell Property DetectCombatAbility Auto State Waiting Event OnTriggerEnter(ObjectReference akActionRef) ;Debug.Notification("Trigger Enter") If akActionRef == PlayerRef GoToState("InTriggerBox") PlayerRef.AddSpell(DetectCombatAbility, false) ;add spell to player silently. ;DetectCombatAbilitys effect start when or if player enters combat. Debug.Notification("Setting custom combat music.") Endif EndEvent EndState State InTriggerBox Event OnTriggerLeave(ObjectReference akActionRef) ;Debug.Notification("Trigger Leave") If akActionRef == PlayerRef GoToState("Waiting") utility.wait(0.1) ;wait a small amount in case player is leaving cell. Wait until new cell is loaded. PlayerRef.RemoveSpell(DetectCombatAbility) Debug.Notification("Setting combat music back to vanilla.") Endif EndEvent EndState The script that goes on the DetectCombatAbility's magic effect. Have it extend ActiveMagicEffect: magic effect has condition IsInCombat == 1 run on the player. MusicType Property MyCombatMusic Auto Event OnEffectStart(Actor akTarget, Actor akCaster) ;effect start when player enters combat MyCombatMusic.Add() EndEvent Event OnEffectFinish(Actor akTarget, Actor akCaster) MyCombatMusic.Remove() EndEvent Note that the wiki: https://www.creationkit.com/index.php?title=Add_-_MusicType says that using Add can make the musictype baked into the save. To prevent this, add the conditions: IsInCombat == 1 ANDGetInSameCell <object reference in your cell> == 1 to each of your music tracks in your custom musictype. Have them run on the Player. Also, make sure your custom musictype has a higher priority than the vanilla combat musictype. Ok, have done all this too step by step and it worked once, but now wont work again, even on a new game. I don't get it. Seems like I have only that earlier one that works pretty reliable but would have to set the cell Music Type to Default, not ideal as I can't get that Music trigger script to turn off on Leaving the trigger. Besides it behaves as if you have set the cell to your choice there after anyways, which in turn makes the Combat music trigger to not work at all. What a viscous cycle. I think for now I'm going to leave custom music out of the mod release as is with vanilla music. Later, I can make a mod to provide the custom combat music as an optional download. For folks that want that intended full effect. Actually now that I think about that's probably the better way to go giving that all efforts are not working as desired. Bethesda must of hard coded the cells Music Type so that it's not script friendly at all. Again, thank you Dylbill. And you guys who showed an interest in this issue. Edited June 29, 2021 by Laerithryn Link to comment Share on other sites More sharing options...
dylbill Posted June 29, 2021 Share Posted June 29, 2021 No problem. That is strange that it only worked once. There is another thing to try. I've never had problems using Sound.Play() in my scripts before. So, you could mute the vanilla music when you enter your cell, then handle the music directly in the script. This is a little more setup, but not too complicated. First, make a new Sound Category. You can duplicate the vanilla AudioCategoryMUS category to make yours. Then make new sound descriptors (instead of music tracks) that point to your audio. Make sure the sound descriptor's category is set to the custom Sound Category you made. Then make a sound marker for each descriptor that use the descriptors. These are what will be used in the script. Here's what the triggerbox script looks like: Scriptname MyCombatMus01 extends ObjectReference Actor Property PlayerRef Auto sound[] property MyCustomMusic Auto ;array of sound markers containing sound descriptors (music tracks). Set in the ck. Float[] property MyCustomMusicLengths Auto ;lengths in seconds of the above music tracks. Set in the ck. sound[] property MyCustomCombatMusic Auto ;array of sound markers containing sound descriptors (music tracks). Set in the ck. Float[] property MyCustomCombatMusicLengths Auto ;lengths in seconds of the above music tracks. Set in the ck. SoundCategory Property MyAudioCategoryMUS Auto ;custom audio catagory that the above sound descriptors use SoundCategory Property AudioCategoryMUS Auto ;vanilla music sound category Float Property MusicVolume Auto Hidden ;music volume setting saved when entering trigger box Int Property MyMusicID Auto Hidden ;current sound ID of music track playing from sound.play(MyMusicTrack) Spell Property DetectCombatAbility Auto ;this spell detects when player enters and leaves combat. Auto State Waiting Event OnTriggerEnter(ObjectReference akActionRef) ;Debug.Notification("Trigger Enter") If akActionRef == PlayerRef debug.notification("Player entered trigger box.") GoToState("InTriggerBox") ;we're in the trigger box. Go to state that detects when we leave the trigger box. MusicVolume = Utility.GetIniFloat("fVal2:AudioMenu") ;get current volume that user has set music to debug.notification("MusicVolume = " + MusicVolume) If MusicVolume < 0.0 MusicVolume = 0.0 Endif ;manually fade out vanilla music Float MusicFade = MusicVolume ;use local variable to fade out vanilla music While MusicFade > 0.0 MusicFade -= 0.1 ;subtract 0.01 from musicFade If MusicFade < 0.0 ;limit, music fade can't go below 0 MusicFade = 0.0 Endif AudioCategoryMUS.SetVolume(MusicFade) ;set vanilla music volume to value of musicFade EndWhile AudioCategoryMUS.SetVolume(0.0) ;mute vanilla music MyAudioCategoryMUS.SetVolume(MusicVolume) ;set volume of our custom music category to that of the user music audio setting If PlayerRef.IsInCombat() == false ;if the player isn't in combat PlayCustomMusic() ;play a normal custom music track Endif PlayerRef.AddSpell(DetectCombatAbility, false) ;if player is in combat, this spell will play a combat music track. RegisterForMenu("Journal Menu") ;Use OnMenuClose to detect if user changed the music volume setting. Endif EndEvent EndState State InTriggerBox Event OnTriggerLeave(ObjectReference akActionRef) If akActionRef == PlayerRef debug.notification("Player left trigger box.") GoToState("Waiting") ;go back to waiting state that listens for when we enter the trigger box. PlayerRef.RemoveSpell(DetectCombatAbility) UnregisterForUpdate() FadeOutMusic(MyMusicID) ;current music playing fades out ;manually fade in vanilla music Float MusicFade = 0.0 While MusicFade <= MusicVolume MusicFade += 0.01 ;add 0.01 to MusicFade If MusicFade > MusicVolume ;MusicFade can't go above MusicVolume MusicFade = MusicVolume Endif AudioCategoryMUS.SetVolume(MusicFade) ;Set vanilla music volume to value of MusicFade EndWhile AudioCategoryMUS.SetVolume(MusicVolume) ;Set vanilla music volume to what it was before entering trigger box. UnregisterForMenu("Journal Menu") EndIf EndEvent Event OnUpdate() ;update when a current music track stops playing. If PlayerRef.IsInCombat() PlayCustomCombatMusic() Else PlayCustomMusic() Endif EndEvent Event OnMenuClose(String menuName) Float akMusicVolume = Utility.GetIniFloat("fVal2:AudioMenu") ;get current volume that user has set music to If akMusicVolume > 0.0 ;did the user change the Music Volume Setting? MusicVolume = akMusicVolume AudioCategoryMUS.SetVolume(0.0) ;mute vanilla music MyAudioCategoryMUS.SetVolume(MusicVolume) ;set volume of our custom music category to that of the user music audio setting Endif EndEvent EndState Function PlayCustomCombatMusic() ;play a custom combat music track UnregisterForUpdate() Int M = MyCustomCombatMusic.Length - 1 ;get max entry that can be referenced in the MyCustomCombatMusic array. Int R = Utility.RandomInt(0, M) ;get random index Sound CombatMusic = MyCustomCombatMusic[R] ;get random combat music track from list. Sound.StopInstance(MyMusicID) ;stop current custom music playing MyMusicId = CombatMusic.Play(PlayerRef) ;play combat music RegisterForSingleUpdate(MyCustomCombatMusicLengths[R]) ;register for when the music track will end Debug.Notification("Playing custom combat music") EndFunction Function PlayCustomMusic() UnregisterForUpdate() FadeOutMusic(MyMusicID) ;fade out current music track playing Sound.StopInstance(MyMusicID) ;stop current custom music playing Int M = MyCustomMusic.Length - 1 ;get max entry that can be referenced in the MyCustomMusic array. Int R = Utility.RandomInt(0, M) ;get random index Sound akMusic = MyCustomMusic[R] ;get random combat music track from list. MyMusicId = akMusic.Play(PlayerRef) ;play combat music RegisterForSingleUpdate(MyCustomMusicLengths[R]) ;register for when the music track will end Debug.Notification("Playing custom music.") EndFunction Function FadeOutMusic(Int SoundID) Float MusicFade = 1.0 While MusicFade > 0.01 MusicFade -= 0.01 Sound.SetInstanceVolume(SoundID, MusicFade) EndWhile EndFunction Here's what the magic effect script looks like: Scriptname TM_MagicEffectScript extends ActiveMagicEffect ;magic effect has the condition IsInCombat == 1 run on the player MyCombatMus01 Property TriggerScript Auto ;script attached to trigger box. ;when filling in the CK, choose the cell the trigger box is in and the trigger box reference. Event OnEffectStart(Actor akTarget, Actor akCaster) ;effect starts when player enters combat TriggerScript.PlayCustomCombatMusic() EndEvent Event OnEffectFinish(Actor akTarget, Actor akCaster) ;effect ends when player leaves combat TriggerScript.PlayCustomMusic() EndEvent Again, for the magic effect make sure it's a constant effect, and the spell is ability type. I tested it out and it seems to work pretty well. Link to comment Share on other sites More sharing options...
dylbill Posted June 29, 2021 Share Posted June 29, 2021 Also, one more thing, if you set the music type for your cell to a blank type, so no music plays, it may not be necessary to mute the vanilla music at all in the script, but it might still because i think combat music would still play. Link to comment Share on other sites More sharing options...
Laerithryn Posted June 30, 2021 Author Share Posted June 30, 2021 Sounds promising. I'll definitely have to give it a go after work tonight. Thanks again Dylbill. Link to comment Share on other sites More sharing options...
Laerithryn Posted July 1, 2021 Author Share Posted July 1, 2021 @Dylbill, Ok trying to figure this one out. Self explanatory for the most part I can see but I admit I'm a bit confused by the property names when it comes to filling in those properties. Are the custom ones first then vanilla? It looks like they're mixed. SOUND MARKERS and LENGTHS are listed twice. I assume for MyCombatMus as well as the VanillaCombatMus? Problem is I can't tell which goes where? For clarity can we rename the properties to differentiate stating what they are for like MyCombatMus for custom things and for Vanilla things maybe something like VanCombatMus? MyCombatMusMarkers, VanCombatMusMarkers. MyCombatMusLength, VanCombatMusLength? Link to comment Share on other sites More sharing options...
dylbill Posted July 1, 2021 Share Posted July 1, 2021 For these properties: sound[] property MyCustomMusic Auto ;array of sound markers containing sound descriptors (music tracks). Set in the ck. Float[] property MyCustomMusicLengths Auto ;lengths in seconds of the above music tracks. Set in the ck. sound[] property MyCustomCombatMusic Auto ;array of sound markers containing sound descriptors (music tracks). Set in the ck. Float[] property MyCustomCombatMusicLengths Auto ;lengths in seconds of the above music tracks. Set in the ck. Those are all custom properties. None are vanilla. The MyCustomMusic are your normal music tracks you want to play (out of combat) while in your cell. This is used instead of setting the music normally, because while in the cell all vanilla music will be muted. The MyCustomCombatMusic is the custom combat music (sound markers) that you want to use. The float[] properties after each, you set the lengths for each track for above. Example: let's say in MyCustomMusic you have 0: TrackA1: TrackB 2: TrackC in MyCustomMusicLengths you would put 0: 60.0000000000000 (tells the script TrackA is 1 minute long) 1: 180.00000000000 (tells the script TrackB is 3 minutes long) 2: 120.00000000000 (tell the script trackC is 2 minutes long) the only vanilla property in the script is: SoundCategory Property AudioCategoryMUS Auto ;vanilla music sound category which is used to mute and unmute vanilla music in the script. Link to comment Share on other sites More sharing options...
Laerithryn Posted July 1, 2021 Author Share Posted July 1, 2021 Thank you for clearing that up for me Dylbill. I guess these old eyes just didn't see the obvious, my apologies.At a quick glance I didn't notice the difference between MyCustomMusic and MyCustomCombatMusic. Umm... do I actually place the sound markers in the cell like normal, and if so do they have to be inside a trigger box or just anywhere? And for (Property AudioCategoryMUS Auto ;vanilla music sound category) is this the Music Type selection we would normally choose for our cell? Link to comment Share on other sites More sharing options...
Recommended Posts