Frictional Games Forum (read-only)
Help with 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: Help with script (/thread-17985.html)



Help with script - amusei - 08-27-2012

Hi, guys.

I am trying to call a certain func when the player interacts with a door and the door is not locked. However, the function just keeps repeating when the player interacts and I want it to stop after it is called once. Here is my script.

Code:
void OnStart()
{
SetEntityPlayerInteractCallback("mansion_6", "Fade", false);
}

void Fade(string &in asEntity)
{
    if(GetSwingDoorLocked("mansion_6") == false)
    {
        SetSwingDoorClosed("mansion_3", true, true);
        SetSwingDoorLocked("mansion_3", true, true);
        PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false);
        GiveSanityDamage(10, true);
        StartScreenShake(0.05f, 3.5f, 1.25f, 3.5f);
        FadePlayerRollTo(-50, 33, 33);
        MovePlayerHeadPos(0, -1, 0, 1, 0);
        PlaySoundAtEntity("", "player_bodyfall.snt", "Player", 0, false);
        SetPlayerCrouching(true);
        SetPlayerActive(false);
        FadeOut(7);
        AddTimer("", 13, "Fog");
    }
}

If I change the
SetEntityPlayerInteractCallback("mansion_6", "Fade", false);
to
SetEntityPlayerInteractCallback("mansion_6", "Fade", true);

The "Fade" won't be called if the player has already interacted with the door when it's locked. If it remains "false" it will just continue to repeat (the player will just fade every time he touches the door if it isn't locked and I want him to fade only the first time). Quite a head rush, eh ? Smile . I hope it has a solution Big Grin


RE: Help with script - Adny - 08-27-2012

If you don't mind me asking, what must the player do to activate this event (aside from interacting with the unlocked door)? What must he do prior to that, such as using a key on a door or pulling a lever? Or is the door unlocked from the very start? It feels like you've only posted a small portion of your entire script.


RE: Help with script - amusei - 08-28-2012

(08-27-2012, 10:36 AM)andyrockin123 Wrote: If you don't mind me asking, what must the player do to activate this event (aside from interacting with the unlocked door)? What must he do prior to that, such as using a key on a door or pulling a lever? Or is the door unlocked from the very start? It feels like you've only posted a small portion of your entire script.
Well, he must use a key to unlock the door. My entire scripts is too large to post and I don't think anyone would want to read through that Big Grin Here is the Key Unlock part of the script if you think it will help.

Code:
    void OnStart()
{
AddUseItemCallback("", "key_hall", "mansion_6", "UnlockDoorWithKey", true);
}

void  UnlockDoorWithKey(string &in asItemA, string &in asItemB)
{
    CompleteQuest("keyquest", "KeyQuest");
    SetSwingDoorLocked("mansion_6", false, true);
    PlaySoundAtEntity("", "unlock_door", "mansion_6", 0, false);
    RemoveItem("key_hall");
}



RE: Help with script - Adny - 08-28-2012

The power of variables! Here ya go:


void OnStart()
{
AddUseItemCallback("", "key_hall", "mansion_6", "UnlockDoorWithKey", true);
SetEntityPlayerInteractCallback("mansion_6", "Fade", false);
SetLocalVarInt("door_var", 0);
}

void UnlockDoorWithKey(string &in asItem, string &in asEntity)
{
CompleteQuest("keyquest", "KeyQuest");
SetSwingDoorLocked("mansion_6", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_6", 0, false);
RemoveItem("key_hall");
AddLocalVarInt("door_var", 1);
}

void Fade(string &in asEntity)
{
if(GetSwingDoorLocked("mansion_6") == false && GetLocalVarInt("door_var") == 1)
{
SetSwingDoorClosed("mansion_3", true, true);
SetSwingDoorLocked("mansion_3", true, true);
PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false);
GiveSanityDamage(10, true);
StartScreenShake(0.05f, 3.5f, 1.25f, 3.5f);
FadePlayerRollTo(-50, 33, 33);
MovePlayerHeadPos(0, -1, 0, 1, 0);
PlaySoundAtEntity("", "player_bodyfall.snt", "Player", 0, false);
SetPlayerCrouching(true);
SetPlayerActive(false);
FadeOut(7);
AddTimer("", 13, "Fog");
SetLocalVarInt("door_var", 0);
}
}


I added a local variable that is added when the key is used to unlock the door; if the player interacts with the door while it is unlocked it will trigger the event (by adding the variable), then disable it from occuring again by setting the variable back to 0.

Hope that helped!


RE: Help with script - amusei - 08-28-2012

(08-28-2012, 07:12 AM)andyrockin123 Wrote: The power of variables! Here ya go:


void OnStart()
{
AddUseItemCallback("", "key_hall", "mansion_6", "UnlockDoorWithKey", true);
SetEntityPlayerInteractCallback("mansion_6", "Fade", false);
SetLocalVarInt("door_var", 0);
}

void UnlockDoorWithKey(string &in asItem, string &in asEntity)
{
CompleteQuest("keyquest", "KeyQuest");
SetSwingDoorLocked("mansion_6", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_6", 0, false);
RemoveItem("key_hall");
AddLocalVarInt("door_var", 1);
}

void Fade(string &in asEntity)
{
if(GetSwingDoorLocked("mansion_6") == false && GetLocalVarInt("door_var") == 1)
{
SetSwingDoorClosed("mansion_3", true, true);
SetSwingDoorLocked("mansion_3", true, true);
PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false);
GiveSanityDamage(10, true);
StartScreenShake(0.05f, 3.5f, 1.25f, 3.5f);
FadePlayerRollTo(-50, 33, 33);
MovePlayerHeadPos(0, -1, 0, 1, 0);
PlaySoundAtEntity("", "player_bodyfall.snt", "Player", 0, false);
SetPlayerCrouching(true);
SetPlayerActive(false);
FadeOut(7);
AddTimer("", 13, "Fog");
SetLocalVarInt("door_var", 0);
}
}


I added a local variable that is added when the key is used to unlock the door; if the player interacts with the door while it is unlocked it will trigger the event (by adding the variable), then disable it from occuring again by setting the variable back to 0.

Hope that helped!
Thanks. That solved the problem. I will never underestimate the power of variables again!