const string correctCode = "6274";
string playersGuessedCode = "";
void OnStart(){}
void OnEnter()
{
SetLocalVarInt("ButtonsPressed", 0);
for(int i=1; i<=9; i++) {
SetEntityPlayerInteractCallback("PressButton_"+i, "PressedButton", false);
}
}
void PressedButton(string &in entity)
{
int buttonsPressed;
AddLocalVarInt("ButtonsPressed", 1);
playersGuessedCode += GetButtonPressed(entity);
buttonsPressed = GetLocalVarInt("ButtonsPressed");
AddDebugMessage("Buttons Pressed: "+buttonsPressed+" Guessed Code: "+playersGuessedCode, false);
if(playersGuessedCode == correctCode) {
// unlock door or whatever here
for(int i=1; i<=9; i++) {
SetEntityActive("PressButton_"+i, false);
}
ResetCode();
AddDebugMessage("Correct code!", false);
return;
}
if(buttonsPressed == 4) {
ResetCode();
AddDebugMessage("Wrong code!", false);
}
}
void ResetCode()
{
SetLocalVarInt("ButtonsPressed", 0);
playersGuessedCode = "";
}
string GetButtonPressed(string entity)
{
if(entity == "PressButton_1") {
return "1";
}
else if(entity == "PressButton_2") {
return "2";
}
else if(entity == "PressButton_3") {
return "3";
}
else if(entity == "PressButton_4") {
return "4";
}
else if(entity == "PressButton_5") {
return "5";
}
else if(entity == "PressButton_6") {
return "6";
}
else if(entity == "PressButton_7") {
return "7";
}
else if(entity == "PressButton_8") {
return "8";
}
else if(entity == "PressButton_9") {
return "9";
}
else {
return "";
}
}
void OnLeave(){}