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



Lever Machine Help - HoyChampoy - 07-20-2012

Hey Forum,

I am in need of big help, I am hoping someone can easily guide me. So first, I want the player to solve a lever machine puzzle. The code I want is up 12 down 12. When the player gets this correct I want an elevator, that was unable to be used before, to start working. The machine and the elevator are on the same map. I am not very good with variables and stuff. Will someone be willing to guide me? Thanks!

EDIT:

Heres a more specific looking code (If the number is red that means the lever is pulled in that direction.)

III___III____ V____ I____ II____ IV

I____V_____IV____ V____ II____ II


RE: Lever Machine Help - Kreekakon - 07-20-2012

Open up "13_machine_room"'s hps file from the original Amnesia. I recall they had a near identical puzzle in there, so you should be able to get a general idea of what to do from in there.


RE: Lever Machine Help - HoyChampoy - 07-20-2012

(07-20-2012, 11:15 AM)Kreekakon Wrote: Open up "13_machine_room"'s hps file from the original Amnesia. I recall they had a near identical puzzle in there, so you should be able to get a general idea of what to do from in there.
Okay i am almost there, but i just can't get the code I want to work which is up 12 down 12.


RE: Lever Machine Help - Ongka - 07-20-2012

I've done pretty much the same riddle, just with 8 levers.

Anyway, heres the whole script with 6 levers.
Code:
void OnStart()
{
for(int i=1;i<7;i++)
{
SetEntityConnectionStateChangeCallback("lever_"+i, "LeverRiddle");
}
}

void LeverRiddle(string &in asEntity, int alState)
{

    if(alState == 1){
        if(asEntity == "lever_1") SetLocalVarInt("up_"+asEntity, 3);
        else if(asEntity == "lever_2") SetLocalVarInt("up_"+asEntity, 3);
        else if(asEntity == "lever_3") SetLocalVarInt("up_"+asEntity, 5);
        else if(asEntity == "lever_4") SetLocalVarInt("up_"+asEntity, 1);
        else if(asEntity == "lever_5") SetLocalVarInt("up_"+asEntity, 2);
        else if(asEntity == "lever_6") SetLocalVarInt("up_"+asEntity, 4);
        CheckValue(asEntity);
        
        AddDebugMessage("Lever Min & up value: " + GetLocalVarInt("up_value"), false);
    }
    else if(alState == -1){
        if(asEntity == "lever_1") SetLocalVarInt("down_"+asEntity, 1);
        else if(asEntity == "lever_2") SetLocalVarInt("down_"+asEntity, 5);
        else if(asEntity == "lever_3") SetLocalVarInt("down_"+asEntity, 4);
        else if(asEntity == "lever_4") SetLocalVarInt("down_"+asEntity, 5);
        else if(asEntity == "lever_5") SetLocalVarInt("down_"+asEntity, 2);
else if(asEntity == "lever_6") SetLocalVarInt("down_"+asEntity, 2);
        CheckValue(asEntity);
            
        AddDebugMessage("Lever Max & down value: " + GetLocalVarInt("down_value"), false);
    }    
    else if(alState == 0){
        SetLocalVarInt("up_"+asEntity, 0);
        SetLocalVarInt("down_"+asEntity, 0);
                
        AddDebugMessage("Lever Mid", false);
    }
    
    /*All levers correct
     */
    if(GetLocalVarInt("up_value") == 12 && GetLocalVarInt("down_value") == 12)
    {

        for(int i=1;i<7;i++)
        {
            SetLeverStuckState("lever_"+i, GetLeverState("lever_"+i), true);
        }        
    }
}

void CheckValue(string sEntity)
{
    PlaySoundAtEntity("s"+sEntity, "lever_mech_min_max", sEntity, 0.0f, false);
    
    SetLocalVarInt("up_value", 0);
    SetLocalVarInt("down_value", 0);
        
    for(int i=1;i<=6;i++){
        AddLocalVarInt("up_value", GetLocalVarInt("up_lever_"+i));
        AddLocalVarInt("down_value", GetLocalVarInt("down_lever_"+i));
    }
}
There you go! Have fun Wink


RE: Lever Machine Help - HoyChampoy - 07-20-2012

(07-20-2012, 01:57 PM)Ongka Wrote: I've done pretty much the same riddle, just with 8 levers.

Anyway, heres the whole script with 6 levers.
Code:
void OnStart()
{
for(int i=1;i<7;i++)
{
SetEntityConnectionStateChangeCallback("lever_"+i, "LeverRiddle");
}
}

void LeverRiddle(string &in asEntity, int alState)
{

    if(alState == 1){
        if(asEntity == "lever_1") SetLocalVarInt("up_"+asEntity, 3);
        else if(asEntity == "lever_2") SetLocalVarInt("up_"+asEntity, 3);
        else if(asEntity == "lever_3") SetLocalVarInt("up_"+asEntity, 5);
        else if(asEntity == "lever_4") SetLocalVarInt("up_"+asEntity, 1);
        else if(asEntity == "lever_5") SetLocalVarInt("up_"+asEntity, 2);
        else if(asEntity == "lever_6") SetLocalVarInt("up_"+asEntity, 4);
        CheckValue(asEntity);
        
        AddDebugMessage("Lever Min & up value: " + GetLocalVarInt("up_value"), false);
    }
    else if(alState == -1){
        if(asEntity == "lever_1") SetLocalVarInt("down_"+asEntity, 1);
        else if(asEntity == "lever_2") SetLocalVarInt("down_"+asEntity, 5);
        else if(asEntity == "lever_3") SetLocalVarInt("down_"+asEntity, 4);
        else if(asEntity == "lever_4") SetLocalVarInt("down_"+asEntity, 5);
        else if(asEntity == "lever_5") SetLocalVarInt("down_"+asEntity, 2);
else if(asEntity == "lever_6") SetLocalVarInt("down_"+asEntity, 2);
        CheckValue(asEntity);
            
        AddDebugMessage("Lever Max & down value: " + GetLocalVarInt("down_value"), false);
    }    
    else if(alState == 0){
        SetLocalVarInt("up_"+asEntity, 0);
        SetLocalVarInt("down_"+asEntity, 0);
                
        AddDebugMessage("Lever Mid", false);
    }
    
    /*All levers correct
     */
    if(GetLocalVarInt("up_value") == 12 && GetLocalVarInt("down_value") == 12)
    {

        for(int i=1;i<7;i++)
        {
            SetLeverStuckState("lever_"+i, GetLeverState("lever_"+i), true);
        }        
    }
}

void CheckValue(string sEntity)
{
    PlaySoundAtEntity("s"+sEntity, "lever_mech_min_max", sEntity, 0.0f, false);
    
    SetLocalVarInt("up_value", 0);
    SetLocalVarInt("down_value", 0);
        
    for(int i=1;i<=6;i++){
        AddLocalVarInt("up_value", GetLocalVarInt("up_lever_"+i));
        AddLocalVarInt("down_value", GetLocalVarInt("down_lever_"+i));
    }
}
There you go! Have fun Wink

Thanks for helping! but when i put the code in, it only activates when i put in up 6 down 7.


RE: Lever Machine Help - HoyChampoy - 07-20-2012

(07-20-2012, 09:29 PM)HoyChampoy Wrote:
(07-20-2012, 01:57 PM)Ongka Wrote: I've done pretty much the same riddle, just with 8 levers.

Anyway, heres the whole script with 6 levers.
Code:
void OnStart()
{
for(int i=1;i<7;i++)
{
SetEntityConnectionStateChangeCallback("lever_"+i, "LeverRiddle");
}
}

void LeverRiddle(string &in asEntity, int alState)
{

    if(alState == 1){
        if(asEntity == "lever_1") SetLocalVarInt("up_"+asEntity, 3);
        else if(asEntity == "lever_2") SetLocalVarInt("up_"+asEntity, 3);
        else if(asEntity == "lever_3") SetLocalVarInt("up_"+asEntity, 5);
        else if(asEntity == "lever_4") SetLocalVarInt("up_"+asEntity, 1);
        else if(asEntity == "lever_5") SetLocalVarInt("up_"+asEntity, 2);
        else if(asEntity == "lever_6") SetLocalVarInt("up_"+asEntity, 4);
        CheckValue(asEntity);
        
        AddDebugMessage("Lever Min & up value: " + GetLocalVarInt("up_value"), false);
    }
    else if(alState == -1){
        if(asEntity == "lever_1") SetLocalVarInt("down_"+asEntity, 1);
        else if(asEntity == "lever_2") SetLocalVarInt("down_"+asEntity, 5);
        else if(asEntity == "lever_3") SetLocalVarInt("down_"+asEntity, 4);
        else if(asEntity == "lever_4") SetLocalVarInt("down_"+asEntity, 5);
        else if(asEntity == "lever_5") SetLocalVarInt("down_"+asEntity, 2);
else if(asEntity == "lever_6") SetLocalVarInt("down_"+asEntity, 2);
        CheckValue(asEntity);
            
        AddDebugMessage("Lever Max & down value: " + GetLocalVarInt("down_value"), false);
    }    
    else if(alState == 0){
        SetLocalVarInt("up_"+asEntity, 0);
        SetLocalVarInt("down_"+asEntity, 0);
                
        AddDebugMessage("Lever Mid", false);
    }
    
    /*All levers correct
     */
    if(GetLocalVarInt("up_value") == 12 && GetLocalVarInt("down_value") == 12)
    {

        for(int i=1;i<7;i++)
        {
            SetLeverStuckState("lever_"+i, GetLeverState("lever_"+i), true);
        }        
    }
}

void CheckValue(string sEntity)
{
    PlaySoundAtEntity("s"+sEntity, "lever_mech_min_max", sEntity, 0.0f, false);
    
    SetLocalVarInt("up_value", 0);
    SetLocalVarInt("down_value", 0);
        
    for(int i=1;i<=6;i++){
        AddLocalVarInt("up_value", GetLocalVarInt("up_lever_"+i));
        AddLocalVarInt("down_value", GetLocalVarInt("down_lever_"+i));
    }
}
There you go! Have fun Wink

Thanks for helping! but when i put the code in, it only activates when i put in up 6 down 7.


Nevermind it worked Smile


RE: Lever Machine Help - Ongka - 07-20-2012

Good, what did you change?