Frictional Games Forum (read-only)
Lever Machine - 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: Lever Machine (/thread-12211.html)



Lever Machine - Randomguy9900 - 12-31-2011

Sorry I'm asking so many questions if you've noticed me, but I promise when I get everything down I'll give back to the Development Support community.

So I took some ideas from an old thread and came up with this for solving a lever puzzle that is 6 machine levers hanging on a machine (Not regular wall levers)

I put areas above and below them for the entities to collide with and call their corresponding functions.
This is what I have.

Code:
(In the OnStart:
    AddEntityCollideCallback("lever_1", "leverup", "lever1", true, 1);
    AddEntityCollideCallback("lever_2", "leverdown", "lever2", true, 1);
    AddEntityCollideCallback("lever_3", "leverdown", "lever3", true, 1);
    AddEntityCollideCallback("lever_4", "leverup", "lever4", true, 1);
    AddEntityCollideCallback("lever_5", "leverdown", "lever5", true, 1);
    AddEntityCollideCallback("lever_6", "leverup", "lever6", true, 1);
}
///Lever Puzzle

void PerformLeverTaskCompleted()
{
SetSwingDoorLocked("door1", false, false);
SetSwingDoorClosed("door1", false, false);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
PlaySoundAtEntity("", "quest_completed.snt", "Player", 0.5f, false);
StartEffectFlash(1, 0.4, 1);
}

void lever1 (string &in asParent, string &in asChild, int alState)
{
    AddLocalVarInt("Levers", 1);
    CheckLevers();
}
void lever2 (string &in asParent, string &in asChild, int alState)
{
    AddLocalVarInt("Levers", 1);
    CheckLevers();
}
void lever3 (string &in asParent, string &in asChild, int alState)
{
    AddLocalVarInt("Levers", 1);
    CheckLevers();
}
void lever4 (string &in asParent, string &in asChild, int alState)
{
    AddLocalVarInt("Levers", 1);
    CheckLevers();
}
void lever5 (string &in asParent, string &in asChild, int alState)
{
    AddLocalVarInt("Levers", 1);
    CheckLevers();
}
void lever6 (string &in asParent, string &in asChild, int alState)
{
    AddLocalVarInt("Levers", 1);
    CheckLevers();
}

void CheckLevers()
{
    if (GetLocalVarInt("Levers") == 6)    
    {
    PerformLeverTaskCompleted();
    }
}

Everything works as it should, except for the fact that you don't have to actually have to have the puzzle correct in the end, just have each lever in the correct position at some time because it'll add a value each time a lever is put into a position. So how do I get it to subtract that value if it's moved out of position?
I've tried, but I just get errors each time I try to fix this.

~Thank you
RandomGuy



RE: Lever Machine - flamez3 - 12-31-2011

You could just use SetLeverStuckState. This freezes the lever and you cannot move it anymore.




SetLeverStuckState("name of lever", -1,0,1, true);

alState - 0 = not stuck, 1 = at max, -1 = at min 3



If you wanted, couldn't you just put a scriptarea where the lever is and SetLocalVarInt("Levers", -1);
This could cause other problems aswell, such as people detracting over and over that they can't make it add up to a positive value. But then again; it's up to you.


RE: Lever Machine - Randomguy9900 - 12-31-2011

I don't want the levers to become stuck in any state. That would defeat the purpose.
And I guess I don't quite get what your other point is, sorry.

EDIT: I guess I get what you're saying, but the problem would be what you;re stating, you may never get it to be a positive value.