ApeCake 
 
 
		
			Member 
			
			
			
 
			
	Posts: 116 
	Threads: 20 
	Joined: Jun 2012
	
 Reputation: 
4
		
	 | 
	
		
			
Activating a script area 
			 
			
				Hello again. So I thought about something very simple, a script area that activates upon a key pickup. When I walk into the script area nothing happens, but after I picked up the key and walk in it it does something (in this case push the player back) (I had in mind delete the script area after one use). However, after I picked up the key and walked in the area nothing happened. Here's my script. The script area is called "pusharea" and the key "tocarnellroomkey". The area is not active in the beginning obviously. 
 
 
 
void OnStart()  
 
{  
AddEntityCollideCallback("Player", "pusharea", "Push", false, 1); 
SetEntityCallbackFunc("tocarnellroomkey", "OnPickupKey"); 
} 
 
 
//The push script 
void Push(string &in asParent, string &in asChild, int alState) 
{  
PlaySoundAtEntity("", "react_pant.snt", "push", 0, false); 
AddPlayerBodyForce(0, 0, -2000, false); 
} 
 
//The setting-the-area-active script 
void OnPickupKey(string &in asEntity, string &in type) 
{ 
SetEntityActive("pusharea", true); 
PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false); 
} 
 
So my guess is that SetEntityActive doesn't work on script areas? Can anyone improve this or knows what I did wrong? Thanks in advance. 
 
EDIT: If I do the code in a code window, it gets messed up.
			 
			
			
			
				
(This post was last modified: 06-22-2012, 08:31 PM by ApeCake.)
 
				
			 
		 |  
	 
 | 
 
	| 06-21-2012, 04:58 PM  | 
	
		
	 | 
 
 
	
		
		MaZiCUT 
 
 
		
			Senior Member 
			
			
			
 
			
	Posts: 536 
	Threads: 31 
	Joined: Jun 2012
	
 Reputation: 
17
		
	 | 
	
		
			
RE: Activating a script area 
			 
			
				 (06-21-2012, 04:58 PM)ApeCake Wrote:  Hello again. So I thought about something very simple, a script area that activates upon a key pickup. When I walk into the script area nothing happens, but after I picked up the key and walk in it it does something (in this case push the player back) (I had in mind delete the script area after one use). However, after I picked up the key and walked in the area nothing happened. Here's my script. The script area is called "pusharea" and the key "tocarnellroomkey". The area is not active in the beginning obviously. 
 
 
 
void OnStart()  
 
{  
AddEntityCollideCallback("Player", "pusharea", "Push", false, 1); 
SetEntityCallbackFunc("tocarnellroomkey", "OnPickupKey"); 
} 
 
 
//The push script 
void Push(string &in asParent, string &in asChild, int alState) 
{  
PlaySoundAtEntity("", "react_pant.snt", "push", 0, false); 
AddPlayerBodyForce(0, 0, -2000, false); 
} 
 
//The setting-the-area-active script 
void OnPickupKey(string &in asEntity, string &in type) 
{ 
SetEntityActive("pusharea", true); 
PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false); 
} 
 
So my guess is that SetEntityActive doesn't work on script areas? Can anyone improve this or knows what I did wrong? Thanks in advance. 
 
EDIT: If I do the code in a code window, it gets messed up. SetEntityActive works on script areas, i don't really understand what you are trying to achieve but i guess you want a script area to be set to true/false when you collide with another script area?
			  
			
			
 
Hi. 
			
		 |  
	 
 | 
 
	| 06-21-2012, 05:04 PM  | 
	
		
	 | 
 
 
	
		
		Cruzore 
 
 
		
			Senior Member 
			
			
			
 
			
	Posts: 301 
	Threads: 2 
	Joined: Jun 2012
	
 Reputation: 
37
		
	 | 
	
		
			
RE: Activating a script area 
			 
			
				replace AddEntityCollideCallback("Player", "pusharea", "Push", false, 1); 
to under the OnPickupKey function, and it should work. 
  
Edit: and delete the setentityactive for this one, and set it active in the level editor
			
			
			
			
				
(This post was last modified: 06-21-2012, 05:05 PM by Cruzore.)
 
				
			 
		 |  
	 
 | 
 
	| 06-21-2012, 05:04 PM  | 
	
		
	 | 
 
 
	
		
		ApeCake 
 
 
		
			Member 
			
			
			
 
			
	Posts: 116 
	Threads: 20 
	Joined: Jun 2012
	
 Reputation: 
4
		
	 | 
	
		
			
RE: Activating a script area 
			 
			
				 (06-21-2012, 05:04 PM)CrazyArts Wrote:  SetEntityActive works on script areas, i don't really understand what you are trying to achieve but i guess you want a script area to be set to true/false when you collide with another script area? Close, I want the script area to be true when a key is picked up.
			  
			
			
			
		 |  
	 
 | 
 
	| 06-21-2012, 05:05 PM  | 
	
		
	 | 
 
 
	
		
		Adny 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 1,766 
	Threads: 6 
	Joined: Mar 2012
	
 Reputation: 
173
		
	 | 
	
		
			
RE: Activating a script area 
			 
			
				Yes, script areas can in fact be set active/inactive. Quick question though, when "OnPickupKey" is called, does the PlaySoundAtEntity work? If the sound doesn't play, then what I'm about to show you will most likely work; if it does play and the script area doesn't activate, it is a spelling error you made (it's hard to tell because I can't see your level editor   )
 
Anyways, try replacing the "OnPickupKey" function with this:
 
void OnPickupKey(string &in asEntity, string &in asType) 
{ 
	if(asType == "OnPickup") //I'm pretty sure this is what needs to be specified for this function 
	{ 
	SetEntityActive("pusharea", true); 
	PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false); 
	} 
}
			  
			
			
 
I rate it 3 memes. 
			
		 |  
	 
 | 
 
	| 06-21-2012, 05:09 PM  | 
	
		
	 | 
 
 
	
		
		Cruzore 
 
 
		
			Senior Member 
			
			
			
 
			
	Posts: 301 
	Threads: 2 
	Joined: Jun 2012
	
 Reputation: 
37
		
	 | 
	
		
			
RE: Activating a script area 
			 
			
				Nevermind, the real problem is: 
the function has to be called OnPickup. So it's SetEntityCallbackFunc("tocarnellroomkey", "OnPickup"); 
and void OnPickup(string &in asEntity, string &in asType) 
also, like andyrockin123 said, you have to use a if: 
if(asEntity == "tocarnellroomkey") 
{ 
stuff 
}
			 
			
			
			
		 |  
	 
 | 
 
	| 06-21-2012, 05:17 PM  | 
	
		
	 | 
 
 
	
		
		ApeCake 
 
 
		
			Member 
			
			
			
 
			
	Posts: 116 
	Threads: 20 
	Joined: Jun 2012
	
 Reputation: 
4
		
	 | 
	
		
			
RE: Activating a script area 
			 
			
				 (06-21-2012, 05:09 PM)andyrockin123 Wrote:  Yes, script areas can in fact be set active/inactive. Quick question though, when "OnPickupKey" is called, does the PlaySoundAtEntity work? If the sound doesn't play, then what I'm about to show you will most likely work; if it does play and the script area doesn't activate, it is a spelling error you made (it's hard to tell because I can't see your level editor  ) 
 
Anyways, try replacing the "OnPickupKey" function with this: 
 
void OnPickupKey(string &in asEntity, string &in asType) 
{ 
	if(asType == "OnPickup") //I'm pretty sure this is what needs to be specified for this function 
	{ 
	SetEntityActive("pusharea", true); 
	PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false); 
	} 
} Thank you, however the sound actually did play before.
 And FasthunteR, it didn't work unfortunately 
 
Let me try out your new one... you guys are posting solutions too fast!   
			 
			
			
			
				
(This post was last modified: 06-21-2012, 05:18 PM by ApeCake.)
 
				
			 
		 |  
	 
 | 
 
	| 06-21-2012, 05:17 PM  | 
	
		
	 | 
 
 
	
		
		Cruzore 
 
 
		
			Senior Member 
			
			
			
 
			
	Posts: 301 
	Threads: 2 
	Joined: Jun 2012
	
 Reputation: 
37
		
	 | 
	
		
			
RE: Activating a script area 
			 
			
				Or maybe i'm wrong, i hate that type of callback    Just try it out, maybe it works
			  
			
			
			
		 |  
	 
 | 
 
	| 06-21-2012, 05:20 PM  | 
	
		
	 | 
 
 
	
		
		Adny 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 1,766 
	Threads: 6 
	Joined: Mar 2012
	
 Reputation: 
173
		
	 | 
	
		
			
RE: Activating a script area 
			 
			
				An alternative that I see is vastly underused is using the level editor to reduce such scripting complications; if you select any (interactable) entity, in the 2nd tab there is a box labeled "PlayerInteractCallback", just type in the name of your function, and use the syntax: 
 "string &in asEntity" 
 
So the OP can select his key in the editor, type in OnPickupKey for the function then write: 
 
void OnPickupKey(string &in asEntity) 
{ 
 
SetEntityActive("pusharea", true); 
PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false); 
} 
 
 
Just something I thought I'd share since I don't see it used too often, and it's pretty useful for reducing script clutter.
			 
			
			
 
I rate it 3 memes. 
			
		 |  
	 
 | 
 
	| 06-21-2012, 05:23 PM  | 
	
		
	 | 
 
 
	
		
		ApeCake 
 
 
		
			Member 
			
			
			
 
			
	Posts: 116 
	Threads: 20 
	Joined: Jun 2012
	
 Reputation: 
4
		
	 | 
	
		
			
RE: Activating a script area 
			 
			
				 (06-21-2012, 05:23 PM)andyrockin123 Wrote:  An alternative that I see is vastly underused is using the level editor to reduce such scripting complications; if you select any (interactable) entity, in the 2nd tab there is a box labeled "PlayerInteractCallback", just type in the name of your function, and use the syntax: 
"string &in asEntity" 
 
So the OP can select his key in the editor, type in OnPickupKey for the function then write: 
 
void OnPickupKey(string &in asEntity) 
{ 
 
SetEntityActive("pusharea", true); 
PlaySoundAtEntity("", "scare_male_terrified5.snt", "randomatticdoor", 2, false); 
} 
 
 
Just something I thought I'd share since I don't see it used too often, and it's pretty useful for reducing script clutter. Doesn't seem to be working ;_; I have no idea what to do now. I must've made a stupid mistake somewhere or something, however there are no errors...
			  
			
			
			
		 |  
	 
 | 
 
	| 06-21-2012, 05:33 PM  | 
	
		
	 | 
 
 
	 
 |