The mod intends to add a separate "playlist" of music to play in dungeons specifically, done by adding activators to dungeon cells. When you enter one of these cells, the music should start playing instead of whatever other music was playing beforehand, when exiting the cell the music should stop, allowing non-dungeon music to resume playing. Combat is handled differently than vanilla, combat music only plays when the player is hit by an enemy, as to avoid interrupting the music which is playing out of nowhere. As usual, after combat is over, the dungeon music should resume.
Problem is, I can't figure out how to get my scripts to act the way I want them to. Instead of only stopping the music when exiting a dungeon cell, the music will be stopped on ANY cell transition, this includes exterior cell transitions and other such nonsense where it makes no sense. Additionally, dungeon music will stop playing when transitioning from one dungeon cell to another, whereas it should just continue playing as normal.
There's also the issue that the dungeon music never resumes after combat is finished, instead the default explore playlist will start playing afterwards, ruining the atmosphere. Additionally, when the player is in combat for long enough, the dungeon music can randomly start playing again, during combat.
Here are my scripts:
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 and dungeon music isn't already playing, end ; the current music and queue the next track to run after a 1 second timer.if ( NMMw_Glob_NewCell == 1 )if ( NMMw_MusPlaying_Dngn == 0 ); MessageBox "Cell Changed! Ending music and setting timer to 1s" StreamMusic "nmmw/endmusic.mp3" set timer to 1 set NMMw_Glob_NewCell to 0endifendif ; 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; return;endif ; If the PC previously had a target, but no longer has one, we can ; assume they killed it. There may have been more than one NPC in combat ; with them 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 ) returnendifif ( timer == 0 ) set NMMw_MusPlaying_Dngn to 0 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 NMMw_MusPlaying_Dngn to 1 set timer to 103elseif ( randTrack == 1 ) StreamMusic "nmmw/dngn/dngn2.mp3" set NMMw_MusPlaying_Dngn to 1 set timer to 250elseif ( randTrack == 2 ) StreamMusic "nmmw/dngn/dngn3.mp3" set NMMw_MusPlaying_Dngn to 1 set timer to 184elseif ( randTrack == 3 ) StreamMusic "nmmw/dngn/dngn4.mp3" set NMMw_MusPlaying_Dngn to 1 set timer to 186elseif ( randTrack == 4 ) StreamMusic "nmmw/dngn/dngn5.mp3" set NMMw_MusPlaying_Dngn to 1 set timer to 407elseif ( randTrack == 5 ) StreamMusic "nmmw/dngn/dngn6.mp3" set NMMw_MusPlaying_Dngn to 1 set timer to 267elseif ( randTrack == 6 ) StreamMusic "nmmw/dngn/dngn7.mp3" set NMMw_MusPlaying_Dngn to 1 set timer to 279elseif ( randTrack == 7 ) StreamMusic "nmmw/dngn/dngn8.mp3" set NMMw_MusPlaying_Dngn to 1 set timer to 286endifend
Spoiler
begin NMMw_CellChangeDetectionlong celllong scelllong tempshort loadshort debugfloat timerset debug to 1if ( MenuMode ) Returnendif ;NewCell should only equal 1 for one frameif ( NMMw_Glob_NewCell == 1 ); if ( debug == 1 ); MessageBox "Player has changed cell. Reset."; endif set NMMw_Glob_NewCell to 0; set timer to 0endifif ( GetInterior == 0 ) if ( CellChanged == 1 ) set NMMw_Glob_NewCell to 1 Return endifendifset load to 0ifx ( load );game was just reloaded, resave current cell setx cell to xPCCellID xFileRewind "nmmw_newcell" xFileWriteString "nmmw_newcell" cell set load to 0endifset timer to ( timer + GetSecondsPassed )if ( timer <= 0.5 ) ReturnendifxFileRewind "nmmw_newcell"setx scell to xFileReadString "nmmw_newcell"setx cell to xPCCellIDsetx temp to xStringCompare scell cellifx ( temp ) ;means the current cell is different from the stored one xFileRewind "nmmw_newcell" xFileWriteString "nmmw_newcell" cell ifx (debug ); xMessageFix "You have recently entered %s" cell; MessageBox "hee hee hee hee hee hee hee hee hee hee hee hee hee hee hee hee hee hee" endif set NMMw_Glob_NewCell to 1endifset timer to 0 if ( NMMw_Glob_NewCell == 1 )if (ScriptRunning NMMw_Music_Dungeon == 0 )messagebox "Not a dungeon cell, ending dungeon music"streammusic "nmmw\endmusic.mp3"set timer to 1endifif (ScriptRunning NMMw_Music_Dungeon == 1 )Returnendif endifend
Good news is, once these quirks are handled, I can release the dungeon music portion of the mod, and will have a solid foundation for the rest of the mod as well. Thanks for the Help in advance!