str4wberrypanic 
 
 
		
			Member 
			
			
			
 
			
	Posts: 241 
	Threads: 24 
	Joined: Jul 2012
	
 Reputation: 
8
		
	 | 
	
		
			
Having issues w/ script 
			 
			
				Hello guys. I'm having a little problem with a script. This is what's supposed to happen: 
 
The player picks up an item on map A and then he collides with a script area on map B. The script area on map B checks if the player has the item, and if he has, a clock plays a sound. If he hasn't the item, then nothing happens. 
This is the script i'm using: 
 
 
 
//////////////////////////// 
// Run first time starting map 
void OnStart() 
 
{    
 
	AddEntityCollideCallback("Player", "Start_Clock_Area", "Clock_Event", false, 1); 
 
} 
 
void Clock_Event(string &in asParent, string &in asChild, int alState) 
{ 
 if(HasItem("item_screwdriver_2")) 
		{ 
		  AddTimer("", 0.1f, "Useless_Timer"); 
	      PlaySoundAtEntity("", "Clock_Chimes", "clock_grandfather_2", 0, false); 
		} 
		 
			else 
		{ 
			return;	 
		} 
} 
 
void Useless_Timer(string &in asTimer) 
{ 
          RemoveEntityCollideCallback("Player", "Start_Clock_Area"); 
} 
 
 
 
 
 
 
There's also a timer to remove the collision because i want the event to happen only once. I tested this script and nothing happens even if i have the item in the inventory. Any help will be apreciated.
			 
			
			
 
			
		 |  
	 
 | 
 
	| 12-15-2013, 09:52 PM  | 
	
		
	 | 
 
 
	
		
		RaideX 
 
 
		
			Member 
			
			
			
 
			
	Posts: 212 
	Threads: 33 
	Joined: May 2013
	
 Reputation: 
7
		
	 | 
	
		
			
RE: Having issues w/ script 
			 
			
				this may be ur problem: 
try to change this
 if(HasItem("item_screwdriver_2")) 
 
 
to this:
 if(HasItem("item_screwdriver_2") == true) 
 
  
			 
			
			
 
If you don't draw first, you don't get to draw at all...  -The False Shepherd 
			
		 |  
	 
 | 
 
	| 12-15-2013, 09:57 PM  | 
	
		
	 | 
 
 
	
		
		str4wberrypanic 
 
 
		
			Member 
			
			
			
 
			
	Posts: 241 
	Threads: 24 
	Joined: Jul 2012
	
 Reputation: 
8
		
	 | 
	
		
			
RE: Having issues w/ script 
			 
			
				It didn't worked. D: 
I have no idea of how to make this work. Maybe using global variables?
			 
			
			
 
			
		 |  
	 
 | 
 
	| 12-15-2013, 10:22 PM  | 
	
		
	 | 
 
 
	
		
		RaideX 
 
 
		
			Member 
			
			
			
 
			
	Posts: 212 
	Threads: 33 
	Joined: May 2013
	
 Reputation: 
7
		
	 | 
	
		
			
RE: Having issues w/ script 
			 
			
				 (12-15-2013, 10:22 PM)str4wberrypanic Wrote:  It didn't worked. D: 
I have no idea of how to make this work. Maybe using global variables? 
Yes. You could try using global variables. 
 
Sidenote: when you use the AddEntityCollideCallback function you can select if the collidearea should be removed with the "bool abDeleteOnCollide" parameter. So you can remove the whole useless timer thing and just change your collide callback to this:
 AddEntityCollideCallback("Player", "Start_Clock_Area", "Clock_Event", true, 1); 
 
  
			 
			
			
 
If you don't draw first, you don't get to draw at all...  -The False Shepherd 
			
				
(This post was last modified: 12-15-2013, 10:35 PM by RaideX.)
 
				
			 
		 |  
	 
 | 
 
	| 12-15-2013, 10:35 PM  | 
	
		
	 | 
 
 
	
		
		str4wberrypanic 
 
 
		
			Member 
			
			
			
 
			
	Posts: 241 
	Threads: 24 
	Joined: Jul 2012
	
 Reputation: 
8
		
	 | 
	
		
			
RE: Having issues w/ script 
			 
			
				Yeah, i know about this parameter. The thing is: the player collides with that area a lot of times, so it's necessary to check if he has the item every time. If i mark it as " true ", the event wouldn't happen because it would check the player inventory only once and remove the collidecallback. Anyway, i'll try using global variables, thank you.
			 
			
			
 
			
		 |  
	 
 | 
 
	| 12-15-2013, 10:43 PM  | 
	
		
	 | 
 
 
	
		
		Daemian 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 1,129 
	Threads: 42 
	Joined: Dec 2012
	
 Reputation: 
49
		
	 | 
	
		
			
RE: Having issues w/ script 
			 
			
				I think it's working, the sound it's not playing. 
You could check that.
			 
			
			
 
			
		 |  
	 
 | 
 
	| 12-15-2013, 11:00 PM  | 
	
		
	 | 
 
 
	
		
		str4wberrypanic 
 
 
		
			Member 
			
			
			
 
			
	Posts: 241 
	Threads: 24 
	Joined: Jul 2012
	
 Reputation: 
8
		
	 | 
	
		
			
RE: Having issues w/ script 
			 
			
				It's not working. I tried another similar script in which a lot of plates fall from a shelf if the player has the same item. 
  
It's so strange, i don't see any error in this script
			
			
			
 
			
		 |  
	 
 | 
 
	| 12-15-2013, 11:06 PM  | 
	
		
	 | 
 
 
	
		
		Daemian 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 1,129 
	Threads: 42 
	Joined: Dec 2012
	
 Reputation: 
49
		
	 | 
	
		
			
RE: Having issues w/ script 
			 
			
				Can you try your code with these debug messages? 
void OnStart()
  { 
  AddEntityCollideCallback("Player", "Start_Clock_Area", "Clock_Event", false, 1); AddDebugMessage( "OnStart", false ); }
  void Clock_Event(string &in asParent, string &in asChild, int alState) { AddDebugMessage( "Collision with Area", false ); if(HasItem("item_screwdriver_2") == true) { AddDebugMessage( "HasItem=true", false ); AddTimer("", 0.1f, "Useless_Timer"); PlaySoundAtEntity("", "Clock_Chimes", "clock_grandfather_2", 0, false); }
  }
  void Useless_Timer(string &in asTimer) { RemoveEntityCollideCallback("Player", "Start_Clock_Area"); AddDebugMessage( "UselessTimer", false ); } 
 
 
It's your same script with some debug messages.
			  
			
			
 
			
		 |  
	 
 | 
 
	| 12-15-2013, 11:54 PM  | 
	
		
	 | 
 
 
	
		
		Romulator 
 
 
		
			Not Tech Support ;-) 
			
			
			
 
			
	Posts: 3,628 
	Threads: 63 
	Joined: Jan 2013
	
 Reputation: 
195
		
	 | 
	
		
			
RE: Having issues w/ script 
			 
			
				Could you also make sure that your items are named correctly in the Level Editor? Like, item_screwdriver_2 and clock_grandfather_2 are named accordingly. 
Also:
 PlaySoundAtEntity("", "Clock_Chimes.snt", "clock_grandfather_2", 0, false); //Missing .snt extension? 
 
 
I am not 100%, but if you're missing the .snt, I think that wont play the sound :o
			  
			
			
 
Discord: Romulator#0001
![[Image: 3f6f01a904.png]](https://puu.sh/zOxJg/3f6f01a904.png)  
			
		 |  
	 
 | 
 
	| 12-16-2013, 12:54 AM  | 
	
		
	 | 
 
 
	
		
		FlawlessHappiness 
 
 
		
			Posting Freak 
			
			
			
 
			
	Posts: 3,980 
	Threads: 145 
	Joined: Mar 2012
	
 Reputation: 
171
		
	 | 
	
		
			
RE: Having issues w/ script 
			 
			
				Ok. I don't know how far you are. 
 
 
IN MAP1 
 
void OnStart() 
{ 
SetEntityPlayerInteractCallback("item", "ItemCallback", true) 
} 
 
void ItemCallback(string &in asEntity) 
{ 
SetGlobalVarInt("Map2Area", 1); 
} 
 
void OnEnter() 
{ 
 
} 
 
void OnLeave() 
{ 
 
} 
 
____________________________________ 
IN MAP2 
 
void OnStart() 
{ 
AddEntityCollideCallback("Player", "ClockArea", "CollideClockArea", false, 1); 
} 
 
void CollideClockArea(string &in asParent, string &in asCHild, int alState) 
{ 
if(HasItem("item") == true) 
{ 
PlaySoundAtEntity("", "Clock_Chimes.snt", "clock_grandfather_2", 0, false); 
 
} 
} 
 
void OnEnter() 
{ 
if(GetGlobalVarInt("Map2Area") == 1) 
{ 
SetEntityActive("ClockArea", true); 
} 
} 
 
void OnLeave() 
{ 
 
}  
 
I don't know if this works, but try it.
			 
			
			
 
Trying is the first step to success. 
			
		 |  
	 
 | 
 
	| 12-16-2013, 01:30 PM  | 
	
		
	 | 
 
 
	 
 |