I've created a new (not very well tested) version of the script. There is a new variable, but people who are using the old version shouldn't have to change anything for it to keep working (just incase, I'm leaving the original script up).

D2 (sfx_secret) is a new variable that determines the behavior of this script in relation to secrets.

0 = Nothing changes (the default behavior)
1 (only works properly with looping)= The sound will keep playing until all secret flags are gone from the screen.
2 = The sound will not start playing until all secret flags are gone from the screen.

Edit: Erm.... I forgot to mention this only works with secret flags 16-32 for the moment. When I'm not so lazy, I'll probably add the item triggers in here. That's a lot of tedious listing.

Code:
// --------------------------------------
// SCRIPT: SFX Player 2.0
// --------------------------------------
// DESCRIPTION
// This script will play a sound effect
// specified by the user. It is capable
// of crude looping when a delay is specified.
// --------------------------------------
// USER ARGUMENTS
// D0 (sfx_slot)
// 	This is the slot number of the sfx you will be playing.
// D1 (sfx_delay)
//	This is the delay between each play of the SFX *in TICS*.
//	**Leaving this at zero will make the SFX only play once.**
//	There are no REAL sound effects that are 0 tics long, after all.
//	Most people will want to set this to the length of the sfx.
//	SECOND TO TIC CONVERSION: Seconds / (1/60) OR Seconds / 0.0166
//	Alternatively (or if I got that wrong), just check things in the ZQuest F9 dialog.
//D2 (sfx_secret)
//	This determines how the sound effect interacts with secret flags.
//	0 = Do nothing.
//	1 = Play until secret trigger (only works correctly when D1 is filled in)
//	2 = Wait until secret trigger to play
//	NOTE: This script only checks layer 0 secret flags.
// --------------------------------------

// #####This is the main code that ZQuest will execute#####

import "std.zh" // Import the standard ZScript supplimentary file.

ffc script sfx_player {
	// Secret checking function
	bool SecretFlags(){
		int max_combos = 176; // Is this right?
		for (int i = 0; i < max_combos; i++)// Loop through all combos on the screen.
			{
				// Check for Inherit combo secret flags
				if (Screen->ComboI[i] >= CF_SECRETS01 && Screen->ComboI[this->Data] <= CF_SECRETS16)
					{
						return true;
					}//!End check for inherit flags
				// Check for placeable secret flags
				else if (Screen->ComboF[i] >= CF_SECRETS01 && Screen->ComboF[this->Data] <= CF_SECRETS16)
					{
						return true;
					}//!End check of normal flags
			}//!End of for loop that loops through all the combos
		return false; // If the function gets this far, then there are no secret flags remaining on the screen.
	}//!End secret checking function

	// Running function
	void run(int sfx_slot, int sfx_delay, int sfx_secret) { // Begin run function.
		int counter = 0; // This is the counter that will be used.
						 // It's used to produce the delay specified.
		int secret_state = sfx_secret; // Set secret_state to the value of what the person entered for sfx_secret
						 
		while(secret_state == 2) // While loop that executes while sfx_secret is 2. Essentially, waits for secrets to trigger.
		{
			// Check to see if the inherit secret flags are there.
			if (SecretFlags())
			{
				Waitframe(); // If so, keep waiting.
			}
			else
			{
				secret_state = 0; // Else, allow the script to continue.
			}//!End of if statement
		}//!End of while loop that waits for secret to trigger
		
		// ##############
		do{ // Run this block of code once before checking the status of sfx_delay.
			if (secret_state == 1)
			{
				if (!SecretFlags()) // SecretFlags() must be false for this statement to be true.
				{
					Quit();//End the script
				}//!End check for SecretFlags state
			}//!End check for secret_state
				
			if (counter == 0) // If the counter is zero, play the sfx in this iteration of the loop.
			{
				Game->PlaySound(sfx_slot); // Play sound # "sfx_slot." This action happens each time this is executed.
				counter = sfx_delay; // (Re)start the counter by setting it to sfx_delay.
			}//!End if statement for counter
			else
			{
				counter--; // Subtract one tic from the counter
			}//!End else statement for counter
			Waitframe(); // Makes the script wait a frame before looping again.
		}while(sfx_delay != 0);//! End of internal do-while loop. If sfx_delay is not 0, it will loop until the ffc is terminated.
	}//! End of run function
}//! End of ffc script
After being annoyed at how I could only check the state of secrets on a screen indirectly, I decided to just write a function that sort of does it. It checks to see if there are any secret flags or secret inherit flags on layer 0, then returns a boolean value to represent this. In other words, all tiered secrets must be completed before the sound will start or stop. I may or may not fix that in the future, but it's stuck like that for now.