Frictional Games Forum (read-only)
Monster disappears after loop - 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)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Monster disappears after loop (/thread-20563.html)



Monster disappears after loop - Romulator - 03-01-2013

Now, let me say that I'm sure this is really simple and I have just done something silly in my code :3

Quite simply, there is a long corridor with a few rooms on each side allowing you to hide if you are quick enough to get inbetween each one. In this corridor, I have 12 pathnodes for 1 monster, which I want to continuously walk up and down the corridor.

I can get him to the 12th, then back to the 1st, but when he gets back to the 12th, he disappears.

This is my code:
Code:
void OnStart()
    {
        AddEntityCollideCallback("Player", "ScriptArea_1", "monsterspawn", true, 1);
    }
void monsterspawn(string &in asParent, string &in asChild, int alState)
    {
    SetEntityActive("servant_grunt_1", true);
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_1", 2, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_2", 0, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_3", 0, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_4", 0, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_5", 0, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_6", 0, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_7", 0, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_8", 0, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_9", 0, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_10", 0, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_11", 0, "");
    AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_12", 4, "");
    for (int i = 1; i < 13; i++)
            {
                AddEnemyPatrolNode("servant_grunt_1","PathNodeArea_"+i, 0, "");
            }
    }

Of course, I'm nowhere near finished on my CS, this is the first level xP but its not my first, and I'm always looking for improvement.


RE: Monster disappears after loop - ghostelom - 03-01-2013

the monster should disappear


RE: Monster disappears after loop - Romulator - 03-01-2013

(03-01-2013, 03:49 PM)ghostelom Wrote: the monster should disappear

Yes, it does.
But I want it to loop continuously... forever... and ever... and ever... (until the player exits the map actually, because he wont be able to return Smile )


RE: Monster disappears after loop - Adrianis - 03-01-2013

In that function, you are setting up path 1 - 12 then 1 - 12 again, which is why he goes twice before dissapearing. If you want to set those 12 up again, you need it to collide with a script area that will call that function again - if he is going to collide with the first area again, then you need to set the area to not delete after the collide (you have 'true', should be 'false')

Also, you only need the for... loop in there, as that will set up the same path nodes as all the previous individual ones you typed


RE: Monster disappears after loop - Your Computer - 03-02-2013

Continually adding patrol nodes to the monster is excessive and unnecessary to meet the desired result. All you have to do is modify the monster entity variables. Since you're using the grunt, you're going to have to make a copy of the grunt so that it doesn't overwrite the original grunt. You do this by making a copy of the ENT file that represents the grunt, give it a different file name so that the original does not take its place, then edit the ENT in a plain-text editor.

Under user defined variables, you add
Code:
<Var Name="AutoRemoveAtPathEnd" Value="false" />

You may also want to increase the activation distance of the monster to prevent premature deactivation of the monster. Then in the level editor replace the grunt with the modified grunt. This also requires that the custom_stories folder is listed in the resources.cfg file.

Note that if you choose to edit the modified grunt in the model editor, it'll undo the manual changes to the ENT file if you save. Meaning, you'll have to add the code again.


RE: Monster disappears after loop - Romulator - 03-02-2013

(03-01-2013, 08:02 PM)Adrianis Wrote: In that function, you are setting up path 1 - 12 then 1 - 12 again, which is why he goes twice before dissapearing. If you want to set those 12 up again, you need it to collide with a script area that will call that function again - if he is going to collide with the first area again, then you need to set the area to not delete after the collide (you have 'true', should be 'false')

Also, you only need the for... loop in there, as that will set up the same path nodes as all the previous individual ones you typed
Thanks for that Big Grin Works like a charm!
(03-02-2013, 01:34 AM)Your Computer Wrote: Continually adding patrol nodes to the monster is excessive and unnecessary to meet the desired result. All you have to do is modify the monster entity variables. Since you're using the grunt, you're going to have to make a copy of the grunt so that it doesn't overwrite the original grunt. You do this by making a copy of the ENT file that represents the grunt, give it a different file name so that the original does not take its place, then edit the ENT in a plain-text editor.

Under user defined variables, you add

You may also want to increase the activation distance of the monster to prevent premature deactivation of the monster. Then in the level editor replace the grunt with the modified grunt. This also requires that the custom_stories folder is listed in the resources.cfg file.

Note that if you choose to edit the modified grunt in the model editor, it'll undo the manual changes to the ENT file if you save. Meaning, you'll have to add the code again.
I was just coming back to say that it worked, so I no longer require assistance, but thanks for this input. It may help later if I choose to add another Grunt to the room, dumping the old one so it uses some more sexy path nodes into the rooms itself Big Grin I'll give reputation for you both Smile