I'm not sure why the GetSoundPlaying functions would need a '== 1.00'. To the scripting engine "if ( x )" is basically the same thing as "if ( x != 0 )", but if changing it worked for you.
For the music stream being broken, be sure the logic of your script is correct. Make sure you understand what is happening on each step and then you should know where the problem arises. From looking at them it seems when the PC is hit it will stream "endmusic", which I assume is a 1 second silent track used to stop the current music stream. After that it doesn't actually use a StopScript command though, so it will continue on through the script and try to play the dungeon music as shown in the 'if ( playOnce == 0 )' block. That explains why the music continues to play after combat begins. You may want to change this section as so:
if ( pcHit ) set playOnce to 0 set timer to 1 StreamMusic "nmmw/endmusic.mp3" StartScript NMMw_CombatReactivator_Dungeon StopScript NMMw_Music_Dungeon returnendif
The should make your music stop, but then you need to be sure that what's happening in the reactivator script makes sense as well.
if ( InCombat == 0 ) returnelseif ( ScriptRunning "NMMw_Music_Dungeon" == 0 ) StartScript NMMw_Music_Dungeonendif
This section on your second script isn't doing what I believe you want it to do. It checks if the player has a combat target and if not it does nothing, but if so it restarts your original script.
That means at the moment your scripts sort of play out like this:
1. Player gets hit
2. Music stops and 2nd script starts
3. The 2nd scripts sees the player has no combat target
4. So it (the 2nd script) restarts the first script
5. Keeps repeating from step 1 in a loop
Remember "InCombat" will always be 0 until the player actually attacks something, so it's not really a reliable way to detect when combat ends.
Here's how I would rewrite the whole thing, also combining both scripts into one as I don't really see any reason to split the job into two. It's hard for me to actually test this as I don't have all the details of your mod nor the actual music files, but I think it should work for the most part. There will still be some minor issues detecting when combat ends, but the only way I can see around that would be to store all NPC references in arrays and constantly monitor each one to see when they leave combat, which wouldn't be very FPS friendly. I included lots of comments and messageboxes to try and explain whats going on.
Spoiler begin NMMw_Music_Dungeon; State Variablesfloat timershort pcHitshort pcCombatshort prevTargshort scanRefsshort randTrack; MWSE Variableslong pcReflong pcTarglong npcReflong npcTargfloat npcTemp ; When player enters the cell, end the current music and queue the next ; track to run after a 1 second timer.if ( CellChanged ) MessageBox "Cell Changed! Ending music and setting timer to 1s" StreamMusic "nmmw/endmusic.mp3" set timer to 1endif ; Continuously detect for when player gets hit in combat.if ( pcTarg == 0 ) set pcHit to 1 if ( Player->GetSoundPlaying "Health Damage" ) elseif ( Player->GetSoundPlaying "destruction hit" ) elseif ( Player->GetSoundPlaying "frost_hit" ) elseif ( Player->GetSoundPlaying "shock hit" ) elseif ( Player->GetSoundPlaying "Light Armor Hit" ) elseif ( Player->GetSoundPlaying "Medium Armor Hit" ) elseif ( Player->GetSoundPlaying "Heavy Armor Hit" ) elseif ( Player->GetSoundPlaying "Hand to Hand Hit" ) elseif ( Player->GetSoundPlaying "Hand to Hand Hit 2" ) else set pcHit to 0 endifendif ; If the player does get hit whilst he wasn't already in combat, end the ; current music and queue the next check to run after a 15s timer. If he ; was already in combat however, we don't need to restart the battle music, ; so in that case only restart the timer back to 15s.if ( pcHit ) if ( pcCombat ) set timer to 15 else MessageBox "Player has been attacked from outside of combat! Ending music and setting timer." set pcCombat to 1 StreamMusic "nmmw/endmusic.mp3" set timer to 15 endif returnendif ; Continuously detect for when the player attacks someone else in combat.setx pcRef to xGetRef "Player"setx pcTarg to pcRef->xGetCombat ; If the player attacks a target from outside of combat, end the current ; music and prevent the rest of the script from processing so long as the ; player still has said combat target.ifx ( pcTarg ) set prevTarg to 1 if ( pcCombat == 0 ) MessageBox "Player attacked a target from outside of combat! Ending music and setting timer." set pcCombat to 1 StreamMusic "nmmw/endmusic.mp3" endif returnendif ; If the PC previously had a target, but no longer has one, we can ; assume he killed it. There may have been more than one NPC in combat ; with him though, so to be sure combat is over we must scan them all.ifx ( prevTarg ) set scanRefs to 5 whilex ( scanRefs ) set scanRefs to ( scanRefs - 1 ) ifx ( npcRef ) setx npcRef to xNextRef npcRef else setx npcRef to xFirstNPC endif ifx ( npcRef ) ; If the NPC is dead then we needn't do any scan for it. xSetRef npcRef set npcTemp to GetHealth if ( npcTemp <= 0 ) return endif ; We don't need to scan NPCs that are very far away either. xSetRef npcRef set npcTemp to ( GetDistance Player ) if ( npcTemp > 7000 ) return endif ; For everything else, find out if it's in combat or not. setx npcTarg to npcRef->xGetCombat if ( npcTarg ) MessageBox "Other NPCs are still in combat! Resetting timer to 15s." set prevTarg to 0 set npcRef to 0 set timer to 15 endif return endif set scanRefs to 0 endwhile MessageBox "Player target dead and no other NPCs in combat! Stopping timer." set prevTarg to 0 set timer to 0endif; Don't play any new music whilst the timer is still active.if ( timer > 0 ) set timer to ( timer - GetSecondsPassed ) returnendif; If the player doesn't have a target and hasn't been hit within the last 15; seconds, we can assume combat has ended.set pcCombat to 0; Once the timer has finished and combat is over, play a random music track.MessageBox "Timer Finished! Starting random dungeon track."set randTrack to Random 7if ( randTrack == 0 ) StreamMusic "nmmw/dngn/dngn1.mp3" set timer to 103elseif ( randTrack == 1 ) StreamMusic "nmmw/dngn/dngn2.mp3" set timer to 250elseif ( randTrack == 2 ) StreamMusic "nmmw/dngn/dngn3.mp3" set timer to 184elseif ( randTrack == 3 ) StreamMusic "nmmw/dngn/dngn4.mp3" set timer to 186elseif ( randTrack == 4 ) StreamMusic "nmmw/dngn/dngn5.mp3" set timer to 407elseif ( randTrack == 5 ) StreamMusic "nmmw/dngn/dngn6.mp3" set timer to 267elseif ( randTrack == 6 ) StreamMusic "nmmw/dngn/dngn7.mp3" set timer to 279elseif ( randTrack == 7 ) StreamMusic "nmmw/dngn/dngn8.mp3" set timer to 286endifend
If for some reason it doesn't work you could PM the esp and I can take a better look.