Frictional Games Forum (read-only)
[SCRIPT] How to make a "Wait" in the script. - 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: [SCRIPT] How to make a "Wait" in the script. (/thread-14684.html)

Pages: 1 2


How to make a "Wait" in the script. - iFondue - 04-10-2012

Hello, I'm pretty new to this forum and i have a question. Huh


I already searched in the forum for answers, but I didn't find anything.
I know that the title is a little complicated, but I am going to explain what I mean... Blush

Idea: I am working on a custom story for a week now, but now I am stuck at this problem. I made the player look at the corridor (StartPlayerLookAt). Now I want to light always 2 lamps, lamp after lamp when i enter "ScriptArea_1". But i want that between the lightning of the lamps is always like 0.5 seconds...

I know that i have to do that with a timer (I think? Big Grin), but I don't know how....

Could someone expain? Tongue


This is my script:


Run when entering map
void OnEnter()

{
AddEntityCollideCallback("Player" , "ScriptArea_1" , "LightOn" , true , 1);
}


void LightOn(string &in asParent, string &in asChild, int alState)
{
AddEntityCollideCallback("Player" , "ScriptArea_1" , "LightOn" , true , 1);
StartPlayerLookAt("LookFrame", 20, 50, "");
SetLampLit("candlestick_1", true, true);
SetLampLit("candlestick_2", true, true);

Wait 0.5 Seconds

Light Lamp 3 and 4 (SetLampLit)

Wait 0.5 Seconds

Light Lamp 4 and 5
(SetLampLit)

.......

StopPlayerLookAt();
}

I think you got the idea... ?


Greets

-iFondue


RE: How to make a "Wait" in the script. - Putmalk - 04-10-2012

Here's how I would do it:

Code:
void LightOn(string &in asParent, string &in asChild, int alStat)
{
      AddEntityCollideCallback("Player" , "ScriptArea_1" , "LightOn" , true , 1);
    
    StartPlayerLookAt("LookFrame", 20, 50, "");
    
    SetLampLit("candlestick_1", true, true);
    
    SetLampLit("candlestick_2", true, true);
      

      AddTimer("light1", 0.5f, "TimerLight");
      AddTimer("light2", 1, "TimerLight");
      AddTimer("stopeffects", 1.2f, "TimerLight");

}

void TimerLight(string &in asTimer)
{

       if(asTimer == "light1")
       {
            //Light Lamp 3 and 4 (SetLampLit);
       }
       if(asTimer == "light2")
       {
            //Light Lamp 4 and 5 (SetLampLit)
       }
       if(asTimer == "stopeffects")
       {
            StopPlayerLookAt();
       }
}



RE: How to make a "Wait" in the script. - iFondue - 04-10-2012

Hey, thank you very much for your fast reply.

It now looks like this:


void LightOn(string &in asParent, string &in asChild, int alStat)
{
AddEntityCollideCallback("Player" , "ScriptArea_1" , "LightOn" , true , 1);

StartPlayerLookAt("LookFrame", 20, 50, "");

SetLampLit("candlestick_1", true, true);

SetLampLit("candlestick_2", true, true);


AddTimer("light1", 0.5f, "TimerLight");
AddTimer("light2", 1, "TimerLight");
AddTimer("stopeffects", 1.2f, "TimerLight");

}

void TimerLight(string &in asTimer)
{

if(asTimer == "light1")
{
SetLampLit("candlestick_3", true, true);
SetLampLit("candlestick_4", true, true);
}
if(asTimer == "light2")
{
SetLampLit("candlestick_5", true, true);
SetLampLit("candlestick_6", true, true);
}
if(asTimer == "stopeffects")
{
StopPlayerLookAt();
}
}


Unfortunately the other lamps won't light. Did I do something wrong? Did I forget something?


Greets

-iFondue


RE: How to make a "Wait" in the script. - Putmalk - 04-10-2012

I just double checked the code...it should be fine...

Could you add a test SetMessage or something inside the if statements to make sure they're running?



RE: How to make a "Wait" in the script. - iFondue - 04-10-2012

Hmmmm... I tried to do a PlaySoundAtEntity but I couldn't hear anything.... Any ideas?


Greets

-iFondue


RE: How to make a "Wait" in the script. - Putmalk - 04-10-2012

I'm having trouble understanding why there's a problem because I performed a similar solution in my own map, here's just a snippet:

Code:
    AddTimer("opendoor", 0.25f, "TimerOpenDoor");
    AddTimer("lightsout", 1, "TimerOpenDoor");
    AddTimer("stopeffects", 2, "TimerOpenDoor");
    
    StartScreenShake(0.007f,2, 0.25f,1);
    FadePlayerFOVMulTo(1.5, 0.5f);
    
}

void TimerOpenDoor(string &in asTimer)
{

    if(asTimer == "stopeffects")
    {
        
        FadePlayerFOVMulTo(1, 1);
        PlaySoundAtEntity("breath", "react_breath.snt", "Player", 1.0 / 0.75f, false);
        return;
    }
    if(asTimer == "lightsout")
    {
        SetLocalVarInt("lightsout", 1);
        for(int i=4;i<=6;i++)
            SetLampLit("chandelier_simple_short_"+i, false, true);
        for(int i=0;i<=6;i++)
            SetLampLit("LampBlownOut_"+i, false, true);
        PlaySoundAtEntity("breath2", "react_breath.snt", "Player", 1.0 / 1, false);
        return;
    }
    
    PlaySoundAtEntity("Wind", "general_wind_whirl", "Player", 2, false);
    PlaySoundAtEntity("scare", "react_scare.snt", "Player", 0.75f, false);
    
    SetSwingDoorClosed("castle_4", false, false);
    SetSwingDoorDisableAutoClose("castle_4", true);
    
    AddTimer("castle_4", 0.01f, "TimerSwingDoor");
    
    GiveSanityDamage(10, true);

}

^^

And that works just fine. Is the code working correctly? The function TimerLight isn't working? This is weird....

Outside the if statements, in TimerLight, put a command. If that doesn't work, then the whole function isn't working, and it's just an error when calling it.

Oh yeah, so I don't forget, is the script working at all? Are other functions working correctly?



RE: How to make a "Wait" in the script. - iFondue - 04-10-2012

Well, this is how it looks right:


void TimerLight(string &in asTimer)
{

if(asTimer == "light1")
{
SetLampLit("candlestick_3", true, true);
SetLampLit("candlestick_4", true, true);
}
if(asTimer == "light2")
{
SetLampLit("candlestick_5", true, true);
SetLampLit("candlestick_6", true, true);
}
if(asTimer == "stopeffects")
{
StopPlayerLookAt();
}
}


It's correct isn't it?
There is no error, when starting, it's just that the light's won't lit....

Is there another way to do it, or did I do something wrong?



Greets

-iFondue


RE: How to make a "Wait" in the script. - Putmalk - 04-10-2012

Copied the code into Programmer's Notepad so I can see it easier, let's see...

void LightOn(string &in asParent, string &in asChild, int alStat) should be

void LightOn(string &in asParent, string &in asChild, int alState), try that....

Also, In your LightOn function, you're creating an entity collide callback to LightOn, how come? Shouldn't that be placed in OnStart()?



RE: How to make a "Wait" in the script. - iFondue - 04-10-2012

Okay, I changed the State.
But what has to go to OnStart () ? Only the LightOn function?


Greets

-iFondue


RE: How to make a "Wait" in the script. - Putmalk - 04-10-2012

(04-10-2012, 06:27 PM)iFondue Wrote: Okay, I changed the State.
But what has to go to OnStart () ? Only the LightOn function?


Greets

-iFondue
Nah, "AddEntityCollideCallback("Player" , "ScriptArea_1" , "LightOn" , true , 1);" does.

Generally, you put your callbacks in the OnStart function, unless you want that event to happen at a specific time, at which you'll put it in a different place.