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



Machine Lever Problem... - sasukeroxxx - 11-29-2011

Hi, im Brazilian, sorry for bad english :3

so,

I'm trying to run a combination of levers on the machine, I tried but could not find tutorials,and I was improvising and comparing with others to see if it worked, but I can not at all.Here is my script out, what's wrong with it? D: the levers are: L1, 2,3,4,5,6 ... I wanted the combination would be: up, up, down, up, down, up. that the machine would be the sum, 11up and 8 down. Help please '-'


Code:
void OnStart(){
}

void Levers(string &in asEntity, int alState){    /*Set values depending on up/down postion or 0 for middle     */    if(alState == -1){        if(asEntity == "L1") SetLocalVarInt("up_"+asEntity, 3);        else if(asEntity == "L2") SetLocalVarInt("up_"+asEntity, 3);        else if(asEntity == "L3") SetLocalVarInt("up_"+asEntity, 5);        else if(asEntity == "L4") SetLocalVarInt("up_"+asEntity, 1);        else if(asEntity == "L5") SetLocalVarInt("up_"+asEntity, 2);        else if(asEntity == "L6") SetLocalVarInt("up_"+asEntity, 4);                CheckValue(asEntity);            }    else if(alState == 1){        if(asEntity == "L1") SetLocalVarInt("down_"+asEntity, 1);        else if(asEntity == "L2") SetLocalVarInt("down_"+asEntity, 5);        else if(asEntity == "L3") SetLocalVarInt("down_"+asEntity, 6);        else if(asEntity == "L4") SetLocalVarInt("down_"+asEntity, 5);        else if(asEntity == "L5") SetLocalVarInt("down_"+asEntity, 2);        else if(asEntity == "L6") SetLocalVarInt("down_"+asEntity, 2);                CheckValue(asEntity);    }            else if(alState == 0){        SetLocalVarInt("up_"+asEntity, 0);        SetLocalVarInt("down_"+asEntity, 0);        }            if(GetLocalVarInt("up_value") == 11 && GetLocalVarInt("down_value") == 8){        SetEntityActive("ShardDoor", false);        GiveSanityBoost();        PlayMusic("02_puzzle.ogg", false, 0.7f, 0, 10, false);        PlaySoundAtEntity("door_safety_open", "door_safety_open.snt", "Player", 0.0f, false);        }}
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_L"+i));        AddLocalVarInt("down_value", GetLocalVarInt("down_L"+i));    }}

void OnEnter(){    PlayMusic("18_amb.ogg", true, 1, 2.0f, 0, false);    }
void OnLeave(){    StopMusic(2,0);}



RE: Machine Lever Problem... - flamez3 - 11-30-2011

Could you space out your hps file?


RE: Machine Lever Problem... - GreyFox - 11-30-2011

Not sure if I set up correctly, but I didn't change anything just tryed to sort it out.

Hopefully you can help him now falmez3

Code:
void OnStart()
{

}

void Levers(string &in asEntity, int alState)
{  
    /*Set values depending on up/down postion or 0 for middle     */    if(alState == -1)    
    if(asEntity == "L1") SetLocalVarInt("up_"+asEntity, 3);        
     else if(asEntity == "L2") SetLocalVarInt("up_"+asEntity, 3);  
     else if(asEntity == "L3") SetLocalVarInt("up_"+asEntity, 5);        
     else if(asEntity == "L4") SetLocalVarInt("up_"+asEntity, 1);        
     else if(asEntity == "L5") SetLocalVarInt("up_"+asEntity, 2);        
     else if(asEntity == "L6") SetLocalVarInt("up_"+asEntity, 4);                
     CheckValue(asEntity);            
}    

else if(alState == 1)
{    
    if(asEntity == "L1") SetLocalVarInt("down_"+asEntity, 1);        
    else if(asEntity == "L2") SetLocalVarInt("down_"+asEntity, 5);        
     else if(asEntity == "L3") SetLocalVarInt("down_"+asEntity, 6);        
     else if(asEntity == "L4") SetLocalVarInt("down_"+asEntity, 5);        
     else if(asEntity == "L5") SetLocalVarInt("down_"+asEntity, 2);        
     else if(asEntity == "L6") SetLocalVarInt("down_"+asEntity, 2);                
     CheckValue(asEntity);    
}            

else if(alState == 0)
{    
    SetLocalVarInt("up_"+asEntity, 0);        
    SetLocalVarInt("down_"+asEntity, 0);        
}            
if(GetLocalVarInt("up_value") == 11 && GetLocalVarInt("down_value") == 8)
{    
    SetEntityActive("ShardDoor", false);        
    GiveSanityBoost();        
    PlayMusic("02_puzzle.ogg", false, 0.7f, 0, 10, false);        
    PlaySoundAtEntity("door_safety_open", "door_safety_open.snt", "Player", 0.0f, false);        
}
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_L"+i));        
    AddLocalVarInt("down_value", GetLocalVarInt("down_L"+i));    }
}

void OnEnter()
{    
    PlayMusic("18_amb.ogg", true, 1, 2.0f, 0, false);    
}
void OnLeave()
{    
    StopMusic(2,0);
}




RE: Machine Lever Problem... - flamez3 - 11-30-2011

(11-30-2011, 03:55 AM)GreyFox Wrote: Not sure if I set up correctly, but I didn't change anything just tryed to sort it out.

Hopefully you can help him now falmez3

Code:
void OnStart()
{

}

void Levers(string &in asEntity, int alState)
{  
    /*Set values depending on up/down postion or 0 for middle     */    if(alState == -1)    
    if(asEntity == "L1") SetLocalVarInt("up_"+asEntity, 3);        
     else if(asEntity == "L2") SetLocalVarInt("up_"+asEntity, 3);  
     else if(asEntity == "L3") SetLocalVarInt("up_"+asEntity, 5);        
     else if(asEntity == "L4") SetLocalVarInt("up_"+asEntity, 1);        
     else if(asEntity == "L5") SetLocalVarInt("up_"+asEntity, 2);        
     else if(asEntity == "L6") SetLocalVarInt("up_"+asEntity, 4);                
     CheckValue(asEntity);            
}    

else if(alState == 1)
{    
    if(asEntity == "L1") SetLocalVarInt("down_"+asEntity, 1);        
    else if(asEntity == "L2") SetLocalVarInt("down_"+asEntity, 5);        
     else if(asEntity == "L3") SetLocalVarInt("down_"+asEntity, 6);        
     else if(asEntity == "L4") SetLocalVarInt("down_"+asEntity, 5);        
     else if(asEntity == "L5") SetLocalVarInt("down_"+asEntity, 2);        
     else if(asEntity == "L6") SetLocalVarInt("down_"+asEntity, 2);                
     CheckValue(asEntity);    
}            

else if(alState == 0)
{    
    SetLocalVarInt("up_"+asEntity, 0);        
    SetLocalVarInt("down_"+asEntity, 0);        
}            
if(GetLocalVarInt("up_value") == 11 && GetLocalVarInt("down_value") == 8)
{    
    SetEntityActive("ShardDoor", false);        
    GiveSanityBoost();        
    PlayMusic("02_puzzle.ogg", false, 0.7f, 0, 10, false);        
    PlaySoundAtEntity("door_safety_open", "door_safety_open.snt", "Player", 0.0f, false);        
}
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_L"+i));        
    AddLocalVarInt("down_value", GetLocalVarInt("down_L"+i));    }
}

void OnEnter()
{    
    PlayMusic("18_amb.ogg", true, 1, 2.0f, 0, false);    
}
void OnLeave()
{    
    StopMusic(2,0);
}


Thanks for that Big Grin, OP; do you want it so there's a specific order for the levers to go down (eg. lever 3 cant go down until level 1 and 2 are in their correct position) or you want it so they can go down in any order but some have to go up and some have to go down?


RE: Machine Lever Problem... - sasukeroxxx - 12-05-2011

in any order...


RE: Machine Lever Problem... - flamez3 - 12-06-2011

Do this:

void OnStart
{
SetLocalVarInt("Var1", 0);
SetEntityConnectionStateChangeCallback("L1", "lever_func1");
SetEntityConnectionStateChangeCallback("L2", "lever_func2");
SetEntityConnectionStateChangeCallback("L3", "lever_func3");
SetEntityConnectionStateChangeCallback("L4", "lever_func4");

SetEntityConnectionStateChangeCallback("L5", "lever_func5");
SetEntityConnectionStateChangeCallback("L6", "lever_func6");
}


void lever_func1(string &in asEntity, int alState)
{
if (alState == 1) //up
{
AddLocalVarInt("Var1", 1);
func01();
}
}


void lever_func2(string &in asEntity, int alState)
{
if (alState == 1) //up
{
AddLocalVarInt("Var1", 1);
func01();
}
}


void lever_func3(string &in asEntity, int alState)
{
if (alState == 1) //up
{
AddLocalVarInt("Var1", 1);
func01();
}
}


void lever_func4(string &in asEntity, int alState)
{
if (alState == 1) //up
{
AddLocalVarInt("Var1", 1);
func01();
}
}


void lever_func5(string &in asEntity, int alState)
{
if (alState == 1) //up
{
AddLocalVarInt("Var1", 1);
func01();
}
}



void lever_func6(string &in asEntity, int alState)
{
if (alState == 1) //up
{
AddLocalVarInt("Var1", 1);
func01();
}
}

void func01()
{
if(GetLocalVarInt("Var1") == 6)
{
what you want to happen here
}
}

I'm not sure whether -1= drag up and 1 = drag down so test this before :3


RE: Machine Lever Problem... - Your Computer - 12-06-2011

Here's one way of doing it (warning: this code is untested):

PHP Code:
// up, up, down, up, down, up
const int[] complex_lever_states = {-1, -11, -11, -1};

void OnStart()
{
    for (
int i 17; ++i)
        
SetEntityConnectionStateChangeCallback("L"+i"ComplexLeverPuzzle");
}

void ComplexLeverPuzzle(string &in entityint state)
{
    
SetLocalVarInt("ComplexLever_"+entitystate);
    
CheckComplexLeverStates();
}

void CheckComplexLeverStates()
{
    for (
int i 17; ++i)
    {
        if (
GetLocalVarInt("ComplexLever_L"+i) != complex_lever_states[i-1])
            return;
    }

    
SetEntityActive("ShardDoor"false);
    
GiveSanityBoost();
    
PlayMusic("02_puzzle.ogg"false0.7f010false);
    
PlaySoundAtEntity("door_safety_open""door_safety_open.snt""Player"0.0ffalse);




RE: Machine Lever Problem... - sasukeroxxx - 12-07-2011

Oh god, works. I was really stuck on this :X and had no idea how to make it work. hehe thank you all for this Smile i am nearly to finish my custom map Big Grin