Frictional Games Forum (read-only)
Help needed with SetEntityActive in custom story - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+--- Thread: Help needed with SetEntityActive in custom story (/thread-53444.html)



Help needed with SetEntityActive in custom story - hagridas - 01-03-2017

Hello. I decided to make a custom story. I am green at scripting, however i can make some simple things like key that unlocks specific doors n stuff. Today i tried to make a script where a monster spawns when player collides with ScriptArea, walks abit and then despawns at certain pathnode. The monster spawns, walks, however it doesnt despawn i tried multiple times watched multiple videos but it doesnt work. I will appreciate any help. My script:

void OnStart()
{
AddEntityCollideCallback("Player", "area", "monster", true,1);
AddEntityCollideCallback("grunt", "PathNodeArea_12", "CollideStop", true, 1);
}

void monster(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("grunt",true);
AddEnemyPatrolNode("grunt", "PathNodeArea_1", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_2", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_3", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_4", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_5", 4, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_6", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_7", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_8", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_9", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_10", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_11", 0.001, "");
AddEnemyPatrolNode("grunt", "PathNodeArea_12", 0.001, "");
}

void CollideStop(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("grunt", false);
}

THANK YOU !!!


RE: Help needed with SetEntityActive in custom story - Spelos - 01-03-2017

Alright, a few things. I'll order them by their relevance to your case:

WHY IT DOESN'T WORK
While you are creating a collision callback for the enemy, a path node is just a single point in the world. It is just a directional helper, a flag if you will, that the enemies use to calculate their path towards their destination. Collision can be calculated with things that actually take up space. Such as Script Areas.

Tell me more:
Spoiler below!

Collisions are calculated based on a position and size of an entity. With those, we can calculate the volume of this object as well as detect if two of them intersect. However, in the case of a single point that has no volume (like a PathNode or Point), you cannot determine this intersection. Moreover, things like entering the intersection, being in it and leaving would have to in a way trigger at the same time or multiple times if single point intersection would be allowed.


HOW TO MAKE IT WORK
Instead of referencing the last PathNode, create a script area there. The enemy will collide with that area.

WHAT TO THINK ABOUT
Enemies disappear on their own once far enough from a player & at the end of their patrol instructions.

(!) SCRIPT RELATED WARNINGS AND TIPS
  • Your function "monster" isn't really telling you much about what it does. Consider changing the name (for your own sake) to something descriptive like "StartHallMonsterEvent"
  • Based on general convention, Function names start with a Capital letter.
  • Consider adding the Collide callback when needed, creating the enemy collision callback in the "monster" function itself.
  • Your "CollideStop" function might be generalized. Meaning it could be called "EnemyDisableTrigger" and instead of
    PHP Code:
    void EnemyDisableTrigger(string &in asParentstring &in asChildint alState)
    {
    SetEntityActive("grunt"false);

    can use the asParent variable to determine what to despawn. That would allow you to add the callback to any number of monsters you want, and each that would collide would get despawned.
    PHP Code:
    // The parameters of this function can also be simplified (although not necessary)
    void EnemyDisableTrigger(string parentstring childint state)
    {
    SetEntityActive(parentfalse); // Actually, the monster might be a child of the collision... Not sure there.




RE: Help needed with SetEntityActive in custom story - hagridas - 01-04-2017

It is working now, thanks alot! I thought Amnesia is dead and didn't expect anyone to reply, but WOW your reply was big and helpful Big Grin Thanks again, everything is working fine now. Ill definately check your Youtube channel for some tutorials n stuffTongue


RE: Help needed with SetEntityActive in custom story - FlawlessHappiness - 01-04-2017

(01-04-2017, 10:11 AM)hagridas Wrote: I thought Amnesia is dead and didn't expect anyone to reply

Don't worry.
We're still a small group of people here!