Want to know how you spawn monsters and make them patrol your map?
To start with, add a monster from the "enemy" folder in "entities" in the level editor. Brute or grunt is recommended for this tutorial. Place it anymore in your map, click on it and click on the "active" box. We DONT want him to be active from start. Remember to name the monster. I will call it "grunt". Click on "Entity" and you can see 2 options. One of them says "Disable triggers". Activate it and that means the monster will ignore the player and sounds you are making. Only recommended for cut-scenes and moments you dont want the monster to be distracted by other sounds. "Hallucination" is exactly what it says. The monster will be a hallucination and will disapear once the player is close enough to the monster.
Now, use the "Areas" tool and select "Script\". Drag the script any where you want (the monster will be activated once the player touch this script). Name it, or keep the original name. To make it simple, I will call it "script\" This is the command we are going to work with:
AddEntityCollideCallback("Player", "script\", "monster", true, 1);
AddEntityColideCallback is always used if you want something to happen when the player is touching something. A script is the most common thing to use. First field is who you want to activate the event. Name it "Player" and the player will be the one to active it. Second field is what the player is touching. I decided to call it "script\". The third field is the callback. What we want the game to do once the player have touched the trigger. I will call it "monster" to make it simple.
The fourth field is if you want this to happen once. If false, the player can trigger as many times he like. True is recommended. The fifth field is if we want this to happen once the player have touched the trigger, if the player is inside the trigger or if the player is leaving the trigger. Leave it "1". Much easier.
Now go to your level editor again and select the "Areas" tool and select "PathNode". The pathnode is where you want your monster to go to. It's important to place it as close to the ground as possible and make it linear! I recommend you to create one node and then copy that one and move it forward in a stright line to not confuse the monster! Also, you dont need to create a node for every step the monster is taking. But the monster will patrol faster if you have few nodes. Name the nodes what ever you want. To make it simple, I will call them node_1, node_2, node_3 etc.
Now, let's make make the callback
The Callback is what you want the game to do once the player have touched the script.
void monster(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("grunt",true);
AddEnemyPatrolNode("grunt","node_1",0,"");
AddEnemyPatrolNode("grunt","node_2",0,"");
AddEnemyPatrolNode("grunt","node_3",0,"");
}
Just continue to copy the same commands and continue the same way if you have more nodes in your map.
SetEntityActive is the entitiy you want to activate. The monster in this case.
AddEnemyPatrolNode is the nodes you have placed in your map. First field is the monster (grunt), second field is where he is supposed to go. Third field is how long he will stand at each node before moving on to the next one and the last field is the animation he is using while moving. Keep it blank!
Now we have a monster and he is moving to the nodes we want. But what if we want the monster to go away after awhile?
Let's see how that works. To start with, copy this command:
AddEntityCollideCallback("grunt","stop","CollideStop",true,1);
First field is the person or entity we want to touch the trigger. The monster in this case (grunt). Second field is the script we want him to touch. I named it "stop". Third field is the callback. Leave the other two fields as they are.
The callback is:
void CollideStop(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("grunt",false);
}
What do we want to happen? We want the grunt to go away. The command is called "SetEntityActive" but since we want him to be disabled, type "false" in the second field instead of "true", First field is ofcourse the entity we want to be disabled. If this is going to work, make sure the monster is going to touch the script by putting the last node behind the "stop" script.
This is how it will look like once everything is done:
void OnStart()
{
AddEntityCollideCallback("Player", "script\", "monster", true,1);
AddEntityCollideCallback("grunt","stop","CollideStop",true,1);
}
void monster(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("grunt",true);
AddEnemyPatrolNode("grunt","node_1",0,"");
AddEnemyPatrolNode("grunt","node_2",0,"");
AddEnemyPatrolNode("grunt","node_3",0,"");
}
void CollideStop(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("grunt",false);
}
Thanks for the information! I didn't know how to make the enemies disappear, and this helped. :D
No problem ;)
The grunt won't activate
What about void OnEnter and OnLeave?
Okay it works now thank you.
Alright good. No problem :3
Can the "FUNCTION"
AddEntityCollideCallback("PLAYER", "AREA", "FUNCTION", true, 1);
have to be a specific name or you can name it what ever you want?
Can be what ever you want.
I have copied script from you but when i load my map its says unexpected end of file.can you give me a true script for it?
This is a "true script". The error you have can be anywhere in the script file, not just from this.
This comment is currently awaiting admin approval, join now to view.
hey can you make amnesia machine for pigs style custom for me and add enemies hallucination
This comment is currently awaiting admin approval, join now to view.