Frictional Games Forum (read-only)

Full Version: Machine Lever Problem...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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);}
Could you space out your hps file?
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);
}

(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?
in any order...
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
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);

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