User Tag List

Results 1 to 10 of 10

Thread: Simple Script: SFX Player

  1. #1
    Lynel Nick's Avatar
    Join Date
    Oct 2001
    Location
    I don't remember...
    Posts
    1,918
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    2,815
    Level
    17
    vBActivity - Bars
    Lv. Percent
    25.34%

    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.

    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.

  2. #2
    Lynel Majora's Avatar
    Join Date
    Mar 2006
    Age
    32
    Posts
    1,197
    Mentioned
    24 Post(s)
    Tagged
    7 Thread(s)
    vBActivity - Stats
    Points
    4,385
    Level
    20
    vBActivity - Bars
    Lv. Percent
    93.35%

    Cool Re: Simple Script: SFX Player

    I will test this script, and if it works as you say it does, you just saved my quest!

  3. #3
    Wizrobe Freedom's Avatar
    Join Date
    Jan 2003
    Posts
    4,711
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    10,856
    Level
    30
    vBActivity - Bars
    Lv. Percent
    87.89%

    Re: Simple Script: SFX Player

    Can this be modified to turn the sounds off when a secret is triggered, and visa versa?
    :O)

    ZC information I've compiled and my quests
    Adventure Tileset
    Elise's Zelda Classic

    Don't ever buy an MTD Product, it's cheap over-priced garbage

  4. #4
    Lynel Nick's Avatar
    Join Date
    Oct 2001
    Location
    I don't remember...
    Posts
    1,918
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    2,815
    Level
    17
    vBActivity - Bars
    Lv. Percent
    25.34%

    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.

    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.

  5. #5
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    41
    Posts
    3,389
    Mentioned
    178 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,430
    Level
    24
    vBActivity - Bars
    Lv. Percent
    69.57%

    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.

  6. #6
    Lynel Nick's Avatar
    Join Date
    Oct 2001
    Location
    I don't remember...
    Posts
    1,918
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    2,815
    Level
    17
    vBActivity - Bars
    Lv. Percent
    25.34%

    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.

    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.

  7. #7
    Keese
    Join Date
    Oct 2004
    Age
    37
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    840
    Level
    10
    vBActivity - Bars
    Lv. Percent
    13.06%

    Re: Simple Script: SFX Player

    Quote Originally Posted by Freedom View Post
    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?
    PM me what its new abilities are please, thank you and I mean ZC 2.11 or something like that.

  8. #8
    Gel
    Join Date
    Jan 2015
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    367
    Level
    6
    vBActivity - Bars
    Lv. Percent
    99.81%
    tow error
    variable undeclared at line 38 and 43

    someone can help me

  9. #9
    How many licks to get to the center Chris Miller's Avatar
    Join Date
    Mar 2001
    Location
    of a Tootsie Roll Pop?
    Age
    46
    Posts
    3,510
    Mentioned
    94 Post(s)
    Tagged
    4 Thread(s)
    vBActivity - Stats
    Points
    5,662
    Level
    23
    vBActivity - Bars
    Lv. Percent
    37.91%
    I'm no scripter, but I'm guessing that the script is almost certainly obsolete. It was made eight years ago.

    Download Lands of Serenity today! You will be knocked comatose by its sheer awesomeness.
    The Titan's Quest, best played in the bathroom as the excitement can be somewhat...overwhelming.





    Official AGN Discord Channel

    Official ZC Dev Discord Channel

  10. #10
    Username Kaiser SUCCESSOR's Avatar
    Join Date
    Jul 2000
    Location
    Winning.
    Age
    37
    Posts
    4,436
    Mentioned
    152 Post(s)
    Tagged
    7 Thread(s)
    vBActivity - Stats
    Points
    10,560
    Level
    30
    vBActivity - Bars
    Lv. Percent
    51.7%
    Quote Originally Posted by Nyrox View Post
    tow error
    variable undeclared at line 38 and 43

    someone can help me
    Are you using any other scripts? There doesnt seem to be anything wrong with it.

    (besides the obscene amount of comments)

    Code:
    ffc script sfx_player {
    	void run(int sfx_slot, int sfx_delay) {
    		int counter = 0; 
    		do{ 
    			if (counter == 0) {
    				Game->PlaySound(sfx_slot); 
    				counter = sfx_delay; //reset counter
    			} 
    			else
    				counter--; 
    			Waitframe(); 
    		} while(sfx_delay != 0); //continue while conditions are met
    	}//! End of run function
    }//! End of ffc script

    EDIT: Just saw version 2. A lot more to look through in that one.

    EDIT2: Have you imported std.zh?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social