| 
		
	
		| KHShox   Junior Member
 
 Posts: 28
 Threads: 11
 Joined: Apr 2011
 Reputation: 
0
 | 
			| How do I make an enemy spawn when the player enters a script area? 
 
				I want to make an enemy spawn in the hallway right when the player gets into an area. How could I do this?
			 
 |  |  
	| 04-03-2011, 11:54 PM |  |  
	
		| Austums   Member
 
 Posts: 60
 Threads: 11
 Joined: Mar 2011
 Reputation: 
0
 | 
			| RE: How do I make an enemy spawn when the player enters a script area? 
 
				First make a script area, name it whatever you want. 
In your script file under OnStart, put this
 AddEntityCollideCallback("Player", "Monster_1", "MonsterFunc1", true, 1);
"Monster_1" is the name of my script area. Change it to whatever yours is called. 
"MonsterFunc1" is the name of the function we're going to use later.
 
Oh, I forgot. Make sure the enemy is "disabled" in the editor. Do this by clicking on the enemy and finding the box called "Active" and click it if it's checked.
 
Once all that is done, add this to your script
 void MonsterFunc1(string &in asParent, string &in asChild, int alState){
 SetEntityActive("servant_grunt_1", true);
 }
MonsterFunc1 is the name of your function. The string stuff is just randomness and I don't know what they do, but you need them, lol
 
Replace the name of "servant_grunt_1" with whatever you named your grunt. Voila. Your enemy should appear when you walk into the area script ~_^
			
				
(This post was last modified: 04-04-2011, 12:14 AM by Austums.)
 |  |  
	| 04-04-2011, 12:14 AM |  |  
	
		| KHShox   Junior Member
 
 Posts: 28
 Threads: 11
 Joined: Apr 2011
 Reputation: 
0
 | 
			| RE: How do I make an enemy spawn when the player enters a script area? 
 
				Quote:////////////////////////////// Run when entering map
 void OnEnter()
 {
 
 }
 
 ////////////////////////////
 // Run when leaving map
 void OnLeave()
 {
 
 }
 
 ////////////////////////////
 // Run first time starting map
 void OnStart()
 {
 AddEntityCollideCallback("Player", "DoorClose", "CollideScript", true, 1);
 }
 
 void CollideScript(string &in asParent, string &in asChild, int alState)
 {
 SetSwingDoorClosed("castle_2", true, true);
 
 AddEntityCollideCallback("Player", "DoorClose", "ScriptArea_2", true, 1);
 
 
 GiveSanityDamage(2, true);
 PlaySoundAtEntity("DoorClose", "react_scare.snt", "Player", 0, false);
 
 AddEntityCollideCallback("Player", "Monster", "Spawn", true, 1);
 
 void MonsterFunc1(string &in asParent, string &in asChild, int alState)
 {
 SetEntityActive("Fag", true);
 }
 
 
 
 
 
 
 
There is my whole code after I added your stuff in it. But I got an error upon loading my map.
			 
 |  |  
	| 04-04-2011, 12:34 AM |  |  
	
		| Austums   Member
 
 Posts: 60
 Threads: 11
 Joined: Mar 2011
 Reputation: 
0
 | 
			| RE: How do I make an enemy spawn when the player enters a script area? 
 
				Well... Yeah. It looks like there are a lot of things wrong with your script, tbh.
			 |  |  
	| 04-04-2011, 12:37 AM |  |  
	
		| Pandemoneus   Senior Member
 
 Posts: 328
 Threads: 2
 Joined: Sep 2010
 Reputation: 
0
 | 
			| RE: How do I make an enemy spawn when the player enters a script area? 
 
				Check the link in my sig.
			 
 |  |  
	| 04-04-2011, 12:49 AM |  |  
	
		| KHShox   Junior Member
 
 Posts: 28
 Threads: 11
 Joined: Apr 2011
 Reputation: 
0
 | 
			| RE: How do I make an enemy spawn when the player enters a script area? 
 
				 (04-04-2011, 12:37 AM)Austums Wrote:  Well... Yeah. It looks like there are a lot of things wrong with your script, tbh. Lol, that's what I thought   
  (04-04-2011, 12:49 AM)Pandemoneus Wrote:  Check the link in my sig. I have been there several times. I downloaded all the videos and reviewed them. But they don't answer all of my questions. I don't know how to keep adding commands without having the ones before it mess up, or my game just crashes. 
  (04-04-2011, 12:49 AM)Pandemoneus Wrote:  Check the link in my sig. I have been there several times. I downloaded all the videos and reviewed them. But they don't answer all of my questions. I don't know how to keep adding commands without having the ones before it mess up, or my game just crashes.
			 
 
				
(This post was last modified: 04-04-2011, 12:59 AM by KHShox.)
 |  |  
	| 04-04-2011, 12:57 AM |  |  
	
		| Pandemoneus   Senior Member
 
 Posts: 328
 Threads: 2
 Joined: Sep 2010
 Reputation: 
0
 | 
			| RE: How do I make an enemy spawn when the player enters a script area? 
 
 |  |  
	| 04-04-2011, 10:11 AM |  |  
	
		| iNs   Junior Member
 
 Posts: 21
 Threads: 4
 Joined: Mar 2011
 Reputation: 
0
 | 
			| RE: How do I make an enemy spawn when the player enters a script area? 
 
				What does it?void AddEntityCollideCallback(string& asParentName, string& asChildName, string& asFunction, bool abDeleteOnCollide, int alStates);
It calls a function when two entites collide.
Callback syntax: 
void MyFunc(string &in asParent, string &in asChild, int alState)
asParentName 
internal name of main object
asChildName 
internal name of object that collides with main object
(asterix (*) NOT supported!)
asFunction 
function to call (for example "MyFunction")
abDeleteOnCollide 
delete the callback after it was called?
alStates: 
1 = on enter (when the 2 entities collide) 
-1 = on leave (when they dont collide anymore) 
0 = on enter AND on leave
 
---
I have fixed your code: What do you need to get this code to work?////////////////////////////// Run when entering map
 void OnEnter()
 {
 
 }
 
 ////////////////////////////
 // Run when leaving map
 void OnLeave()
 {
 
 }
 
 ////////////////////////////
 // Run first time starting map
 void OnStart()
 {
 // Player collides with 'AreaCloseDoor' => function 'CloseDoor' is called
 AddEntityCollideCallback("Player", "AreaCloseDoor", "CloseDoor", true, 1);
 
 // Player collides with 'AreaCloseDoor2' => function 'CloseDoor' is called
 // you can remove this callback, when you dont need a 2nd script area
 AddEntityCollideCallback("Player", "AreaCloseDoor2", "CloseDoor", true, 1);
 
 // Player collides with 'MonsterArea' => function 'SpawnMonster' is called
 AddEntityCollideCallback("Player", "MonsterArea", "SpawnMonster", true, 1);
 }
 
 // Player collides with 'AreaCloseDoor'
 void CloseDoor(string &in asParent, string &in asChild, int alState)
 {
 SetSwingDoorClosed("castle_2", true, true);
 GiveSanityDamage(2, true);
 PlaySoundAtEntity("DoorClose", "react_scare.snt", "Player", 0, false);
 }
 
 // Player collides with 'MonsterArea'
 void SpawnMonster(string &in asParent, string &in asChild, int alState)
 {
 SetEntityActive("NotSoScaryMonster", true);
 }
- Script Area named: "AreaCloseDoor " 
- Script Area named: "AreaCloseDoor2 " (optional) 
- Script Area named: "MonsterArea " 
- Your Monster named: "NotSoScaryMonster"
 
--- 
I hope that helps ya.
 
Regards
iNs 
				
(This post was last modified: 04-04-2011, 11:53 AM by iNs.)
 |  |  
	| 04-04-2011, 11:53 AM |  |  
	
		| KHShox   Junior Member
 
 Posts: 28
 Threads: 11
 Joined: Apr 2011
 Reputation: 
0
 | 
			| RE: How do I make an enemy spawn when the player enters a script area? 
 
				Thanks man! This surely does help!
			 
 |  |  
	| 04-04-2011, 08:36 PM |  |  |