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



Scripting problem - JonnyAnomaly - 08-01-2013

I'm trying to make a script to make an enemy randomly appear and disappear, then loop the script. The problem is, after he has been activated once, he never comes back. Here is my script at the moment -

void OnEnter()
{
AddEntityCollideCallback("Player", "ScriptArea_1", "activatemonster1", true, 1);
}

void activatemonster1(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("manhunter_1", true);
AddTimer("", RandFloat(5.0f, 20.0), "deactivatemonster1");
}

void deactivatemonster1(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("manhunter_1", false);
AddTimer("", RandFloat(60.0f, 120.0), "activatemonster1");
}

Would someone be able to tell me why its not repeating itself?


RE: Scripting problem - PutraenusAlivius - 08-01-2013

void OnEnter()
{
AddEntityCollideCallback("Player", "ScriptArea_1", "activatemonster1", true, 1);
}

void activatemonster1(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("manhunter_1", true);
AddTimer("", RandFloat(5.0f, 20.0), "deactivatemonster1");
}

void deactivatemonster1(string &in asTimer)
{
SetEntityActive("manhunter_1", false);
AddTimer("", RandFloat(60.0f, 120.0), "activatemonster1");
}

You had the wrong callback syntax in the first AddTimer call.


RE: Scripting problem - JonnyAnomaly - 08-01-2013

Ah I see, thanks for your help!


RE: Scripting problem - Your Computer - 08-01-2013

PHP Code:
void OnEnter() // should probably be OnStart
{
    
AddEntityCollideCallback("Player""ScriptArea_1""ActivateMonster"true1);
}

void ActivateMonster(string &in asParentstring &in asChildint alState)
{
    if (
asChild == "ScriptArea_1")
        
ActivateMonster("manhunter_1");
}

void ActivateMonster(string &in monster)
{
    
ResetProp(monster);
    
SetEntityActive(monstertrue);
    
AddTimer(monsterRandFloat(5.0f20.0), "DeactivateMonster");
}

void DeactivateMonster(string &in monster)
{
    
SetEntityActive(monsterfalse);
    
AddTimer(monsterRandFloat(60.0f120.0), "ActivateMonster");




RE: Scripting problem - JonnyAnomaly - 08-01-2013

Thanks, I'm still trying to learn the basics of scripting, so many stupid mistakes are made. I'm still at the stage where I punch the air if my map loads without a fatal error.


RE: Scripting problem - DeAngelo - 08-01-2013

As a scripter you'll have to walk the fine balance of figuring things out yourself so you get better, and asking the fine folk here. My general rule of thumb: don't ask until the error is causing you to re-evaluate your goals in life.