RE: Script Error 4.0
void OnStart()
{
//BEGIN LEVER SCRIPT
SetEntityConnectionStateChangeCallback("lever_machine_lever01", "PullLever1");
SetEntityConnectionStateChangeCallback("lever_machine_lever02", "PullLever2");
SetEntityConnectionStateChangeCallback("lever_machine_lever03", "PullLever3");
SetEntityConnectionStateChangeCallback("lever_machine_lever04", "PullLever4");
SetEntityConnectionStateChangeCallback("lever_machine_lever05", "PullLever5");
SetEntityConnectionStateChangeCallback("lever_machine_lever06", "PullLever6");
SetLocalVarInt("Levers", 0);
SetLocalVarInt("Lever1", 0);
SetLocalVarInt("Lever2", 0);
SetLocalVarInt("Lever3", 0);
SetLocalVarInt("Lever4", 0);
SetLocalVarInt("Lever5", 0);
SetLocalVarInt("Lever6", 0);
//END LEVER SCRIPT
}
void PullLever1(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLocalVarInt("Lever1", 1);
AddDebugMessage("Lever 1 is in the right position", false);
PlaySoundAtEntity("", "lever_mech_min_max", asEntity, 0.0f, false);
}
else if(alState == 0)
{
SetLocalVarInt("Lever1", 0);
AddDebugMessage("Lever 1 is in the wrong position", false);
}
else if(alState == -1)
{
SetLocalVarInt("Lever1", 0);
PlaySoundAtEntity("", "lever_mech_min_max", asEntity, 0.0f, false);
}
if(GetLocalVarInt("Lever1") == 1) && GetLocalVarInt("Lever2") == 1) && GetLocalVarInt("Lever3") == 1) && GetLocalVarInt("Lever4") == 1) && GetLocalVarInt("Lever5") == 1) && GetLocalVarInt("Lever6") == 1)
{
AddDebugMessage("SUCCES", false);
PlayMusic("13_puzzle_machine.ogg", false, 1.0f, 0, 1, false);
SetMessage("Messages", "Succes", 5);
SetPlayerSanity(90);
AddPlayerSanity(10);
//
SetGlobalVarInt("SixLeversComplete", 1);
//
SetLeverStuckState("lever_machine_lever01", 1, false);
SetLeverStuckState("lever_machine_lever02", -1, false);
SetLeverStuckState("lever_machine_lever03", -1, false);
SetLeverStuckState("lever_machine_lever04", 1, false);
SetLeverStuckState("lever_machine_lever05", 1, false);
SetLeverStuckState("lever_machine_lever06", -1, false);
AddTimer("", 5, "TouchLeversAfterCompletion");
}
else
{
AddDebugMessage("The levers aren't in the right positions", false);
}
}
This is for OnStart() and Lever 1. Basically, you assign each lever his own local variable, which you set 1 if it's in the right position and 0 if it's not. Then, at each lever movement, you check if ever lever variable is 1, then you do that stuff. This might be the only way, maybe you can decrease the length by calling a function when all lever variables are 1, instead of doing all this in every lever function. Anyway, this one should work. Just add each lever.
|