| 
		
	
		| Plazmater   Member
 
 Posts: 122
 Threads: 24
 Joined: Aug 2013
 Reputation: 
1
 | 
			| Random Looped Sound 
 
				Everyone knows that the sound in game is the most important thing for atmosphere.
 And its not only PlayMusic or PlaySoundAtEntity (with looped "amb" sound).
 
 What i want to do is to create area from where looped snt. sound will be played with intervals.
 (So it can play randomly between every 15-25 secs in loop).
 
 But i have no idea how to script this. Any idea ?
 |  |  
	| 07-25-2014, 03:20 PM |  |  
	
		| i3670   Posting Freak
 
 Posts: 1,308
 Threads: 74
 Joined: Oct 2011
 Reputation: 
36
 | 
			| RE: Random Looped Sound 
 
				void FunctionTimer(string &in asTimer){
 int iArea = RandFloat(1, 7);	<--- if you want the sound to be played at different areas: insert the number of areas.
 float fTime = RandFloat(4.5f,7.5f); <--- insert the number of seconds between timers, in your case 15.0f and 25.0f
 
 PlaySoundAtEntity("NameOfSoundInGame"+iArea , "NameOfSound.snt", "AreaWhereTheSoundPlays"+iArea , 0.0f, false);
 
 AddTimer("TimerName", 5.5f+fTime , "FunctionTimer");
 }
 
 
				
(This post was last modified: 07-25-2014, 03:35 PM by i3670.)
 |  |  
	| 07-25-2014, 03:29 PM |  |  
	
		| Plazmater   Member
 
 Posts: 122
 Threads: 24
 Joined: Aug 2013
 Reputation: 
1
 | 
			| RE: Random Looped Sound 
 
				"int iArea = RandFloat(1, 7);	<--- if you want the sound to be played at different areas: insert the number of areas."
 I cant quite understand that , if i would set it (1, 3) , so it would play sound at original area and 2 others. But at which 2 other areas ? Should I create them and SOMEHOW script it as another areas for the same sound. Or it would randomly found 2 more areas that exist on the map and play it there ?
 
 void FunctionTimer(string &in asTimer)
 {
 int iArea = RandFloat(1, 3);
 float fTime = RandFloat(5f,7f);
 
 PlaySoundAtEntity("afx_spooky_mansion_whisper"+iArea , "afx_spooky_mansion_whisper.snt", "ScriptArea_1"+iArea , 0.0f, false);
 
 AddTimer("TimerName", 1.0f+fTime , "FunctionTimer");
 }
 
 I keep getting error:
 
 FATAL ERROR: Could not load script file 'MyFC/maps/Level1.hps'!
 main (15, 26) : ERR  : Expected ')' or ','
 
				
(This post was last modified: 07-25-2014, 04:54 PM by Plazmater.)
 |  |  
	| 07-25-2014, 04:16 PM |  |  
	
		| Mudbill   Muderator
 
 Posts: 3,881
 Threads: 59
 Joined: Apr 2013
 Reputation: 
179
 | 
			| RE: Random Looped Sound 
 
				When you copy an area, it makes a new one with another number at the end. For example ScriptArea_1 and ScriptArea_2. That allows you to write the name "ScriptArea_" because they both have this name, and then you can, through the script, add all the numbers at the end.
 In this example, the int variable iArea will add the numbers randomly. If you have 10 areas with the same name, just different numbers at the end, then make iArea = RandFloat(1, 10);
 
 Then when you do "ScriptArea_" + iArea in your script, it will add a random number to the name and thus play the sound at a random area, as long as the names match.
 
 PS: I think int iArea needs to use RandInt and not RandFloat because it is an int and not a float.
 
 
				
(This post was last modified: 07-25-2014, 05:05 PM by Mudbill.)
 |  |  
	| 07-25-2014, 05:04 PM |  |  
	
		| Plazmater   Member
 
 Posts: 122
 Threads: 24
 Joined: Aug 2013
 Reputation: 
1
 | 
			| RE: Random Looped Sound 
 
				int iArea = RandInt(1, 3);
 Still the same error.
 |  |  
	| 07-25-2014, 05:10 PM |  |  
	
		| Mudbill   Muderator
 
 Posts: 3,881
 Threads: 59
 Joined: Apr 2013
 Reputation: 
179
 | 
			| RE: Random Looped Sound 
 
				What's your whole script?
 By the way, do not do "ScriptArea_1"+iArea because that will result in ScriptArea_11.
 
 |  |  
	| 07-25-2014, 05:13 PM |  |  
	
		| Plazmater   Member
 
 Posts: 122
 Threads: 24
 Joined: Aug 2013
 Reputation: 
1
 | 
			| RE: Random Looped Sound 
 
				void FunctionTimer(string &in asTimer){
 int iArea = RandInt(1, 3);
 float fTime = RandFloat(5f, 7f);
 
 PlaySoundAtEntity("afx_spooky_mansion_whisper"+iArea, "afx_spooky_mansion_whisper.snt", "ScriptArea_"+iArea, 0.0f, false);
 
 AddTimer("TimerName", 1.0f+fTime, "FunctionTimer");
 }
 |  |  
	| 07-25-2014, 05:17 PM |  |  
	
		| Mudbill   Muderator
 
 Posts: 3,881
 Threads: 59
 Joined: Apr 2013
 Reputation: 
179
 | 
			| RE: Random Looped Sound 
 
				Your error says you have something wrong at line 15. This can't be your whole script because this isn't even 15 lines.
			 
 |  |  
	| 07-25-2014, 05:20 PM |  |  
	
		| Plazmater   Member
 
 Posts: 122
 Threads: 24
 Joined: Aug 2013
 Reputation: 
1
 | 
			| RE: Random Looped Sound 
 
				This is from start:
 
 void LanternEvent(string &in asEntity, string &in type)
 {
 AddPlayerLampOil(70.0f);
 
 SetSwingDoorLocked("mansion_6", false, false);
 PlayMusic("music_mansion_lanternpickup.ogg", false, 1.0f, 0, 0, true);
 }
 
 
 void FunctionTimer(string &in asTimer)
 {
 int iArea = RandInt(1, 3);
 float fTime = RandFloat(5f, 7f);
 
 PlaySoundAtEntity("afx_spooky_mansion_whisper"+iArea, "afx_spooky_mansion_whisper.snt", "ScriptArea_"+iArea, 0.0f, false);
 
 AddTimer("TimerName", 1.0f+fTime, "FunctionTimer");
 }
 |  |  
	| 07-25-2014, 05:23 PM |  |  
	
		| i3670   Posting Freak
 
 Posts: 1,308
 Threads: 74
 Joined: Oct 2011
 Reputation: 
36
 | 
			| RE: Random Looped Sound 
 
				try
 float fTime = RandFloat(5.0f, 7.0f);
 
 Also, don't forget to add the timer in the OnStart or else it won't trigger.
 
 |  |  
	| 07-25-2014, 07:28 PM |  |  |