MrWallas 
 
 
		
			Junior Member 
			
			
			
 
			
	Posts: 2 
	Threads: 1 
	Joined: Jun 2015
	
 Reputation: 
0
		
	 | 
	
		
			
How to make things happen only in a certain area 
			 
			
				I'm using a script based off of Wapez's Custom Ambient Map Scares script. But one thing about the script that I'm finding is that the random things continue to happen even when you're outside of the area. 
I have one area where I want there to be random breath sounds coming from the player but I want it to ONLY happen in that particular area, and stop outside of the area, but then start back up when you enter the area again.
 
Is there any way I can do that?
 
Here's the code, which works as it is right now, but it doesn't do exactly what I want it to do.
 void OnStart() 
{ 
float RandomBreathSoundsTimerNumber = RandFloat( 2.0f, 15.0f ); 
AddTimer("bs_soundstimer_first", RandomBreathSoundsTimerNumber, "RandomBreathSounds"); 
AddEntityCollideCallback("Player", "SlowMoveArea", "ChangeCAMSState", false, 1); 
} 
 
void RandomBreathSounds(string &in asTimer) 
{ 
    if(GetLocalVarString("CAMS_State") == "SlowMoveArea"){ 
        SetLocalVarInt("BS_AreaNumber", RandInt( 1, 4 )); 
        AddDebugMessage("Playing sounds in SlowMoveArea", false); 
    } 
     
    int SS_CountNumber = RandInt( 1, 3 ); 
     
    if( SS_CountNumber == 1 ) PlayGuiSound("react_breath.snt", 1.0f); 
    if( SS_CountNumber == 2 ) PlayGuiSound("react_sigh.snt", 1.0f); 
    if( SS_CountNumber == 3 ) PlayGuiSound("react_breath_slow.snt", 1.0f); 
     
    AddDebugMessage("Played sound at SlowMoveArea", false); 
     
    float RandomBreathSoundsTimerNumber = RandFloat( 2.0f, 15.0f ); 
     
    AddTimer("bs_soundstimer", RandomBreathSoundsTimerNumber, "RandomBreathSounds"); 
     
}
  
			 
			
			
			
				
(This post was last modified: 06-15-2015, 05:10 AM by MrWallas.)
 
				
			 
		 |  
	 
 | 
 
	| 06-15-2015, 05:09 AM  | 
	
		
	 | 
 
 
	
		
		Artsy 
 
 
		
			Member 
			
			
			
 
			
	Posts: 213 
	Threads: 10 
	Joined: Feb 2014
	
 Reputation: 
9
		
	 | 
	
		
			
RE: How to make things happen only in a certain area 
			 
			
				Just put the contents of the timer in a collision callback...?
			 
			
			
			
		 |  
	 
 | 
 
	| 06-15-2015, 08:27 AM  | 
	
		
	 | 
 
 
	
		
		DnALANGE 
 
 
		
			Banned 
			
			
			
 
			
	Posts: 1,549 
	Threads: 73 
	Joined: Jan 2012
	
		
	 | 
	
		
			
RE: How to make things happen only in a certain area 
			 
			
				Try this : 
        void ChangeCAMSState(string &in asEntity, int alState)  { if(alState == 1) { // THIS is where you are IN the specific area. }
  if(alState == -1) { // THIS is where you are OUT the specific area. } } 
 
  
			 
			
			
			
				
(This post was last modified: 06-15-2015, 10:01 AM by DnALANGE.)
 
				
			 
		 |  
	 
 | 
 
	| 06-15-2015, 10:01 AM  | 
	
		
	 | 
 
 
	
		
		Darkfire 
 
 
		
			Senior Member 
			
			
			
 
			
	Posts: 371 
	Threads: 22 
	Joined: May 2014
	
 Reputation: 
15
		
	 | 
	
		
			
RE: How to make things happen only in a certain area 
			 
			
				That's why I don't paste code which I can't understand.  
Try replacing PlayGuiSound function with PlaySoundAtEntity and use the area you want as the entity. Seems you're not too experienced, so make sure to check these functions in the engine scripts site.
			 
			
			
 
			
		 |  
	 
 | 
 
	| 06-15-2015, 10:49 AM  | 
	
		
	 | 
 
 
	
		
		FlawlessHappiness 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 3,980 
	Threads: 145 
	Joined: Mar 2012
	
 Reputation: 
171
		
	 | 
	
		
			
RE: How to make things happen only in a certain area 
			 
			
				To me, the idea is to have an area that starts a repeating timer, and stops a repeating timer. 
 
void CollideCallback(string &in asParent, string &in asChild, int alState) 
{ 
if(alState == 1) //If going inside area. 
{ 
if(GetTimerTimeLeft("Breath") > 0) 
else 
{ 
AddTimer("Breath", 1.0f, "BreathTimer"); 
} 
SetLocalVarInt("BreathTimerVar", 1); 
} 
 
if(alState == -1) //If going outside of area 
{ 
SetLocalVarInt("BreathTimerVar", 0); 
} 
} 
 
void BreathTimer(string &in asTimer) 
{ 
if(GetLocalVarInt("BreathTimerVar") == 1) 
{ 
//PlaySound 
AddTimer("Breath", 1.0f, "BreathTimer"); 
} 
}
			 
			
			
 
Trying is the first step to success. 
			
		 |  
	 
 | 
 
	| 06-15-2015, 11:40 AM  | 
	
		
	 | 
 
 
	
		
		MrWallas 
 
 
		
			Junior Member 
			
			
			
 
			
	Posts: 2 
	Threads: 1 
	Joined: Jun 2015
	
 Reputation: 
0
		
	 | 
	
		
			
RE: How to make things happen only in a certain area 
			 
			
				 (06-15-2015, 10:49 AM)Darkfire Wrote:  That's why I don't paste code which I can't understand.  
Try replacing PlayGuiSound function with PlaySoundAtEntity and use the area you want as the entity. Seems you're not too experienced, so make sure to check these functions in the engine scripts site. 
Yeah, you're right, I'm not too experienced, but I'm capable of learning, I learned how that code, in and of itself, works. I appreciate the suggestion but I really don't appreciate the snarky attitude you seem to be giving me.
			  
			
			
			
				
(This post was last modified: 06-15-2015, 03:26 PM by MrWallas.)
 
				
			 
		 |  
	 
 | 
 
	| 06-15-2015, 02:23 PM  | 
	
		
	 | 
 
 
	
		
		Mudbill 
 
 
		
			Muderator 
			
			
			
 
			
	Posts: 3,881 
	Threads: 59 
	Joined: Apr 2013
	
 Reputation: 
179
		
	 | 
	
		
			
RE: How to make things happen only in a certain area 
			 
			
				I'd say there are two common ways to trigger an event only while in an area. One is to activate it when you enter, then deactivate it when you leave. The other is to run it, but always check if the player is in the area before doing it. The latter is more robust, but there's (as far as I know) no super easy way of checking player collision. You might be able to if you tinker with more than one function though. GetEntitiesCollide does not support Player.  
Here's an example using the activation method (which is much like what has already been suggested):
 void OnStart() {     AddEntityCollideCallback("Player", "SlowMoveArea", "ChangeCAMSState", false, 0);      //Notice I put 0 in the end. This enables both enter and exit events. }
  void ChangeCAMSState(string &in asParent, string &in asChild, int alState) {     if(alState == 1) {         //This will activate once, when you enter the area.          //If you need it to keep happening, add a looping timer here. Like so:         TimerLoop("");     }     else if(alState == -1) {         //This runs when you leave the area.          //If you have a looping timer, use RemoveTimer(); here.     } }
  void TimerLoop(string &in asTimer) {     //Do whatever you want here.     AddTimer("timerloop", 1.0f, "TimerLoop"); //This adds itself everytime, effectively looping.      //The first argument is the internal name you need in order to remove the timer.     //The 1.0f is the tickrate of the loop. If you need your actions to happen often, use a low value.     //Find the balance you need for your event. } 
 
  
			 
			
			
 
			
				
(This post was last modified: 06-15-2015, 02:41 PM by Mudbill.)
 
				
			 
		 |  
	 
 | 
 
	| 06-15-2015, 02:34 PM  | 
	
		
	 | 
 
 
	 
 |