I have a problem with my script. I'm trying to use a script there 3 levers are needed to be pulled down to unlock a door. When I'm using one of the levers, the door unlocks before I've pulled down the two other levers.
I have no idea what's wrong with my script. If you can find what's wrong, please make a comment
.
void OnStart()
{
//-- Leversfunction
SetLocalVarInt("Var_sum1", 0);
SetEntityConnectionStateChangeCallback("lever1", "func_lever1");
SetEntityConnectionStateChangeCallback("lever2", "func_lever2");
SetEntityConnectionStateChangeCallback("lever3", "func_lever3");
}
// -- Levers - open door
void func_lever1(string &in asEntity,
int alState)
{
if (alState == 1)
{
AddLocalVarInt("Var_sum1", 1);
Func_open_gate();
}
}
void func_lever2(string &in asEntity,
int alState)
{
if (alState == 1)
{
AddLocalVarInt("Var_sum1", 1);
Func_open_gate();
}
}
void func_lever3(string &in asEntity,
int alState)
{
if (alState == 1)
{
AddLocalVarInt("Var_sum1", 1);
Func_open_gate();
}
}
void Func_open_gate()
{
if(GetLocalVarInt("Var_sum1") == 3)
{
SetSwingDoorLocked("prison_cellardoor", false, true);
PlaySoundAtEntity("", "unlock_door", "prison_cellardoor", 0, false);
GiveSanityBoostSmall();
}
}