Could I please have some help with a script to loop music within cells?
The aim of the script is to continually loop a certain track of music within a cell as long as the player is within it, and to continue to do so even if the player saves and reloads within the cell.
I've written a script which seems to do its job, but has a few problems I can't seem to fix. Here is the script, which is attached to an activator inside the cell:
Begin NON_VoidMusicSchiz; script to loop music while player is in cell and to continue to loop it even if player saves in-cell and loads game into the cell; this is what the looped sound is for - the script works without it but won't continue to loop music if the player saves and loads the game into the cell; but if player loads game into the cell, the sound won't be playing, the script will pick it up and reset the music variable to trigger the music to loop againfloat timer; menumode can't be blocked because it blocks the sound as well, meaning the music will reset each time you open a menuIf ( GetSoundPlaying, "endrumble" != 1 ) If ( NON_VoidMusic == 2 ) ; this is a global for controlling the music - each music-looped cell has its own unique value Set NON_VoidMusic to 99 ; this is just a random value to trigger the music to re-loop Set timer to 0 EndifEndifIf ( NON_VoidMusic != 2 ) StreamMusic, "NON/NON_Schizotypy.mp3" PlayLoopSound3D, "endrumble" ; the activator this script is attached to is far from the rest of the cell so this sound is inaudible Set NON_VoidMusic to 2 set timer to 0Else set timer to ( timer + getsecondspassed ) if ( timer > 916 ) ; length of music track in seconds + a few seconds set NON_VoidMusic to 99 stopsound, "endrumble" set timer to 0 endifendifEnd
Here are the problems I've been having with the script:
1: When going from one cell with music-looping to another which has an identical script except that it streams different music, the second cell's script sometimes doesn't override the first and the originally looped music keeps playing.
2: When using doors which teleport you to another location within the same cell, sometimes, but not all the time, the music resets.
3: In one of the cells with music looping the music resets itself well before it has finished. It will reset itself at random different points each time. This doesn't happen in any of the other cells. My only possible explanation for this is that I have lots of other sound activators playing in this cell - perhaps they interfere with the sound the script uses?
I'm at a loss as to how to fix them, especially given the random 'on-off' nature of the problems. I'm willing to bet that it's the looped sound which is causing the problems, but I can't think of any other way to make the music continue to loop even if the player loads a game into the cell.
I'd really appreciate any help, either with fixing the problems or finding a more elegant solution to do what I want to do with the music!