Frictional Games Forum (read-only)
CreateEntityAtArea problem - 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: CreateEntityAtArea problem (/thread-9572.html)



CreateEntityAtArea problem - Rapture - 08-03-2011

Is this another one of the functions that need some special need like
Code:
SetSwingDoorClosed
because you can't close a door without using
Code:
AddPropImpulse

I'm trying to do loops (gonna figure it out myself hopefully). I'm testing to create some pots that will be made every 1 second for 10 times, and apparently nothing is being created. I tested out the sound, and I it works correctly.

Code:
    for(int i = 0; i <10; i++)
        AddTimer("T", i, "TimerFunction");
Copied the code from wiki.frictional, couldn't find any loop examples anywhere else or any ones I want.
Code:
void TimerFunction(string &in asTimer)
{
    PlaySoundAtEntity("scare", "react_scare.snt", "Player", 0, false);
    CreateEntityAtArea("Create", "vase01.ent", "ScriptArea_1", false);
}
So can I not create entities at areas? I would find this very sad for my custom story Sad


RE: CreateEntityAtArea problem - Kyle - 08-03-2011

Try this:

Code:
void OnStart()
{
     SetLocalVarInt("Var01", 0); // # of pots made check
     Func01(); // looping function
}
void Func01()
{
     AddTimer("", 1, "Func02");
}
void Func02(string &in asTimer)
{
     if (GetLocalVarInt("Var01") < 11)
     {
          int x = GetLocalVarInt("Var01");
          x = x + 1;
          SetLocalVarInt("Var01", x); // I'm just using one way, there are many other ways to do it
          PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);
          CreateEntityAtArea("Create", "vase01.ent", "ScriptArea_1", false);
          Func01();
     }
}

I was able to implement rocks to be created at random times at random areas and random rock sizes (out of 2). After the 100th or so rock does it start lagging. xD


RE: CreateEntityAtArea problem - Apjjm - 08-03-2011

Rapture, your code should work. Perhaps the entity needs a unique name, though, so try:

Code:
    //Change your first bit of code to this
for(int i = 0; i <10; i++)
AddTimer("T"+i, i, "TimerFunction");

//Change your timer callback to this
void TimerFunction(string &in asTimer)
{
        AddDebugMessage("Creating object Create"+asTimer,false);
    PlaySoundAtEntity("scare", "react_scare.snt", "Player", 0, false);
    CreateEntityAtArea("Create"+asTimer, "vase01.ent", "ScriptArea_1", false);
}

Though note that this will create all the vases at one location. You should create multiple script areas and do the following:
Code:
//Change your first bit of code to this
for(int i = 0; i <10; i++)
AddTimer("_"+(i+1), i, "TimerFunction");

//Change your timer callback to this
void TimerFunction(string &in asTimer)
{
        AddDebugMessage("Creating object Create"+asTimer,false);
    PlaySoundAtEntity("scare", "react_scare.snt", "Player", 0, false);
    CreateEntityAtArea("Create"+asTimer, "vase01.ent", "ScriptArea"+asTimer, false);
}