I've done pretty much the same riddle, just with 8 levers.
Anyway, heres the whole script with 6 levers.
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