Simple Script: SFX Player
I released this at PureZC the day after I made the Inventory Modifier. However, I held it back from here since I figured I'd be making a few other scripts and I was going to bundle them in a single topic. After all, why waste so many topics on these things? However, I now have Twilight Princess distracting me, so I might as well go ahead and do this. :blah:
Once again, this script is nothing amazing, really. It utilizes a do-while loop (my favorite type of loop), but beyond this, this script isn't all that different from other scripts with looping counters. The main reason I created it was so that people could take advantage of the extra sfx slots in ZQuest. There is currently no way to use them outside of scripting.
Copy/Paste from PureZC:
This script pretty much does what the name says: it plays a sound effect. D0 is the sound effect slot that will be played. D1 is a bit more complicated to explain, but it's essentially the delay (in tics) between each play of the sound effect. If you leave this at 0, the sound effect will only play once. I had to add the delay because there is currently no way to determine how long a sound effect is (*hint hint*). Just looping PlaySound(); over and over again would not work by itself, as that would be very bad. As such, you will have to determine for yourselves the proper values to put here for whatever sound effects you want to use. The F9 dialog in ZQuest is a good place to explore possible values. ;)
Code:
// --------------------------------------
// SCRIPT: SFX Player
// --------------------------------------
// 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.
// --------------------------------------
// #####This is the main code that ZQuest will execute#####
ffc script sfx_player {
void run(int sfx_slot, int sfx_delay) { // Begin run function.
int counter = 0; // This is the counter that will be used.
// It's used to produce the delay specified.
do{ // Run this block of code once before checking the status of sfx_delay.
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
Like last time, let me know if there are any problems with this script.
Re: Simple Script: SFX Player
I will test this script, and if it works as you say it does, you just saved my quest!
Re: Simple Script: SFX Player
Can this be modified to turn the sounds off when a secret is triggered, and visa versa?
Re: Simple Script: SFX Player
That's one of the things I've been wondering, myself. Truth be told, I've not messed with FFCs all that much. I'd assume that if you can make the FFC appear and disappear (can secrets do that?), it would be possible to start and stop the script like that. :shrug:
I really need to look into this stuff a bit more, as I encountered a similar question with my Inventory Modifier script. A question to those who might know: Is there a way for scripting to check if secrets have been triggered for a screen? I've looked around, but haven't found anything in the current documentation. If there is indeed such a function, then I can easily fix the script to work with secret triggers.
Re: Simple Script: SFX Player
You can't check directly, but you can take a slightly more roundabout approach: put an inherent secret flag on the combo used by the FFC and make the script watch this->Data to see if it changes.
Re: Simple Script: SFX Player
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. :shrug:
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. :shrug:
Re: Simple Script: SFX Player
Quote:
Originally Posted by
Freedom
Can this be modified to turn the sounds off when a secret is triggered, and visa versa?
Do I have to type it out and then what do I save the script as?