Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I make an enemy spawn when the player enters a script area?
KHShox Offline
Junior Member

Posts: 28
Threads: 11
Joined: Apr 2011
Reputation: 0
#1
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?

[Image: bf3_sig-1298673357.jpg]
04-03-2011, 11:54 PM
Find
Austums Offline
Member

Posts: 60
Threads: 11
Joined: Mar 2011
Reputation: 0
#2
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
Find
KHShox Offline
Junior Member

Posts: 28
Threads: 11
Joined: Apr 2011
Reputation: 0
#3
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.

[Image: bf3_sig-1298673357.jpg]
04-04-2011, 12:34 AM
Find
Austums Offline
Member

Posts: 60
Threads: 11
Joined: Mar 2011
Reputation: 0
#4
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
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#5
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
Find
KHShox Offline
Junior Member

Posts: 28
Threads: 11
Joined: Apr 2011
Reputation: 0
#6
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 Tongue
(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.

[Image: bf3_sig-1298673357.jpg]
(This post was last modified: 04-04-2011, 12:59 AM by KHShox.)
04-04-2011, 12:57 AM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#7
RE: How do I make an enemy spawn when the player enters a script area?

Also use the search function.
http://www.frictionalgames.com/forum/thread-5117.html

04-04-2011, 10:11 AM
Find
iNs Offline
Junior Member

Posts: 21
Threads: 4
Joined: Mar 2011
Reputation: 0
#8
RE: How do I make an enemy spawn when the player enters a script area?

void AddEntityCollideCallback(string& asParentName, string& asChildName, string& asFunction, bool abDeleteOnCollide, int alStates);

What does it?
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:

////////////////////////////
// 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);
}

What do you need to get this code to work?
- 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
Find
KHShox Offline
Junior Member

Posts: 28
Threads: 11
Joined: Apr 2011
Reputation: 0
#9
RE: How do I make an enemy spawn when the player enters a script area?

Thanks man! This surely does help!

[Image: bf3_sig-1298673357.jpg]
04-04-2011, 08:36 PM
Find




Users browsing this thread: 1 Guest(s)