Frictional Games Forum (read-only)
Interacting with item then teleporting to another area 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: Interacting with item then teleporting to another area script? (/thread-24581.html)



Interacting with item then teleporting to another area script? - Artsy - 02-09-2014

Hello there,
I'm working on a custom story and had this cool idea for something which requires script.
It's basically like this:
the player interacts with the lever, the screen fades black and then the player teleports to another area.
I've found script from the Cellar Archives from TDD, which is exactly what I want:

Quote: FadeOut(0.3);

AddTimer("scare", 0.3f, "TimerPlayerReact");
AddTimer("breath", 2.0f, "TimerPlayerReact");
AddTimer("breathl", 4.0f, "TimerPlayerReact");
AddTimer("breathl", 6.0f, "TimerPlayerReact");

AddTimer("TeleportHowl", 0.5f, "TimerTeleportHowl");
AddTimer("TeleportDone", 3.5f, "TimerTelportDone");

PlaySoundAtEntity("stomp","scare_wall_stomp","Player", 0, false);
PlaySoundAtEntity("darkamb","07_amb_breath","Player", 5, true);
PlaySoundAtEntity("wateramb", "ambience_water_no3d.snt", "sound_idle_1", 5, true);

FadePlayerFOVMulTo(4.0f, 4.0f);
SetRadialBlurStartDist(0.1f);
FadeRadialBlurTo(1.0f, 5.0f);

StartEffectFlash(0.2, 0.1,0.3);

FadeGlobalSoundVolume(0, 0.3);
StopMusic(0.3f, 0);
StartScreenShake(0.1, 4.7, 0.05, 0.5);

FadePlayerFOVMulTo(0.5, 3);
}

void TimerPlayerReact(string &in asTimer)
{
if(asTimer == "scare"){
PlayGuiSound("react_scare", 1.0f);
}
else if(asTimer == "breath"){
PlayGuiSound("react_breath", 0.8f);
}
else if(asTimer == "breathl"){
PlayGuiSound("react_breath", 0.5f);
}
}

void TimerTeleportHowl(string &in asTimer)
{
PlaySoundAtEntity("howl","guardian_activated.snt","Player", 0, false);
SetPlayerActive(false);
SetFogActive(true);
}

void TimerTelportDone(string &in asTimer)
{
TeleportPlayer("PlayerStartArea_3");
FadeGlobalSoundVolume(1,2);
SetPlayerActive(true);
FadePlayerFOVMulTo(1.0f, 0.5f);
FadeRadialBlurTo(0.0f, 1.0f);
FadeIn(1.3);

FadePlayerFOVMulTo(1, 1);

StartUpDarkSide();
}

But - I really do want the player to interact with the lever first, before the screen fades black. Help?

Can you give me an example?


RE: Interacting with item then teleporting to another area script? - Mudbill - 02-09-2014

Run the script you want to happen inside a block that is executed when you interact with the lever. One way to do this is to go to the lever's entity tab in the level editor. One of the text boxes should say PlayerInteractCallback. Write a name in there (for example InteractLever).

Then go to your script and make the block for it. From what you quoted, it looks like you cut out the top of it. You can place all of what was originally inside that block inside the new block you made, like this:

Code:
void InteractLever(string &in asEntity)
{
    FadeOut(0.3);

    AddTimer("scare", 0.3f, "TimerPlayerReact");    
    AddTimer("breath", 2.0f, "TimerPlayerReact");    
    AddTimer("breathl", 4.0f, "TimerPlayerReact");
    AddTimer("breathl", 6.0f, "TimerPlayerReact");

    AddTimer("TeleportHowl", 0.5f, "TimerTeleportHowl");    
    AddTimer("TeleportDone", 3.5f, "TimerTelportDone");

    PlaySoundAtEntity("stomp","scare_wall_stomp","Player", 0, false);
    PlaySoundAtEntity("darkamb","07_amb_breath","Player", 5, true);
    PlaySoundAtEntity("wateramb", "ambience_water_no3d.snt", "sound_idle_1", 5, true);

    FadePlayerFOVMulTo(4.0f, 4.0f);
    SetRadialBlurStartDist(0.1f);
    FadeRadialBlurTo(1.0f, 5.0f);

    StartEffectFlash(0.2, 0.1,0.3);

    FadeGlobalSoundVolume(0, 0.3);
    StopMusic(0.3f, 0);
    StartScreenShake(0.1, 4.7, 0.05, 0.5);

    FadePlayerFOVMulTo(0.5, 3);
}

You can keep the rest as it is right now, and that should be it. Let me know if it works out Smile


RE: Interacting with item then teleporting to another area script? - Artsy - 02-09-2014

Ok so I put InteractLever in PlayerInteractCallback and when I pulled the level the screen faded to black ever so quickly (which is what I wanted anyway) but the screen remains black like that and I can hear sounds and stuff.
I most definitely did something wrong in the script AGAIN. Probably forgot to do something. I wrote the code there you gave me and saved the document. I also tried putting the rest of the stuff that was in the Cellar Archives script and it gave me a bunch of errors.

Never mind, I fixed it! I forgot to add the rest of the stuff that was in the original script. Thanks a lot!


RE: Interacting with item then teleporting to another area script? - Mudbill - 02-10-2014

Looking more closely at your script I noticed there is no FadeIn. If you fade out it will remain black until you fade back in.

Generally, it's not recommended to copy over Frictional's script into your own because you have less control over what's going on. You can use it as a reference, but I suggest you write it yourself so you can set it up just how you want.

If you want the screen to fade in again, use FadeIn(1); anywhere in your script after fading out. You may change 1 to any time in seconds for how fast you want it to happen.


RE: Interacting with item then teleporting to another area script? - Artsy - 02-10-2014

Good thing I got it to work just fine either way. I agree that frictional's scripts are complicated and that I don't have much control over them. I deleted the rest of the script that was made by them since I don't need it.