Script Error 4.0 - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: Script Error 4.0 (/thread-16350.html) Pages:
1
2
|
Script Error 4.0 - GoranGaming - 06-20-2012 Can anyone tell my why this script doesn't work, when I have all the levers in the right position, nothing happens! ///////////////////// //BEGIN LEVER SCRIPT ///////////////////// void PullLever1(string &in asEntity, int alState) { if(alState == 1){ AddDebugMessage("Lever 1 is in the right position", false); AddLocalVarInt("Levers", 1); }else{ AddDebugMessage("Lever 1 is in the wrong position", false); } } void PullLever2(string &in asEntity, int alState) { if(alState == -1){ AddDebugMessage("Lever 2 is in the right position", false); AddLocalVarInt("Levers", 1); }else{ AddDebugMessage("Lever 2 is in the wrong position", false); } } void PullLever3(string &in asEntity, int alState) { if(alState == -1){ AddDebugMessage("Lever 3 is in the right position", false); AddLocalVarInt("Levers", 1); }else{ AddDebugMessage("Lever 3 is in the wrong position", false); } } void PullLever4(string &in asEntity, int alState) { if(alState == 1){ AddDebugMessage("Lever 4 is in the right position", false); AddLocalVarInt("Levers", 1); }else{ AddDebugMessage("Lever 4 is in the wrong position", false); } } void PullLever5(string &in asEntity, int alState) { if(alState == 1){ AddDebugMessage("Lever 5 is in the right position", false); AddLocalVarInt("Levers", 1); }else{ AddDebugMessage("Lever 5 is in the wrong position", false); } } void PullLever6(string &in asEntity, int alState) { if(alState == -1){ AddDebugMessage("Lever 6 is in the right position", false); AddLocalVarInt("Levers", 1); }else{ AddDebugMessage("Lever 6 is in the wrong position", false); } } /*void StartMachine(string &in asEntity) { if(GetLocalVarInt("Levers") == 6){ AddDebugMessage("SUCCES", false); }else{ } }*/ void OnStart() { PlaySoundAtEntity("", "13_amb.ogg", "Player", 1.0f, false); 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"); if(GetLocalVarInt("Levers") == 6){ AddDebugMessage("SUCCES", false); }else{ AddDebugMessage("The levers aren't in the right positions", false); } if(ScriptDebugOn()) { GiveItemFromFile("lantern", "lantern.ent"); for(int i=0;i<10;i++){ GiveItemFromFile("tinderbox_"+i, "tinderbox.ent"); } } } void OnEnter() { } void OnLeave() { } A made a video showing the script in action: http://www.youtube.com/watch?v=-6FFj-w3tfo&feature=youtu.be RE: Script Error 4.0 - Cruzore - 06-20-2012 try adding SetLocalVarInt("Levers", 0); in OnStart() RE: Script Error 4.0 - GoranGaming - 06-20-2012 Still Doesn't work RE: Script Error 4.0 - Cruzore - 06-20-2012 PlaySoundAtEntity("", "13_amb.ogg", "Player", 1.0f, false); .ogg is music, .snt is sound. So it's PlayMusic(all the stuff) EDIT!:Another thing: Since the if statement for all 6 levers is inside OnStart(), it's only checked once. Get the if inside every lever function. RE: Script Error 4.0 - GoranGaming - 06-20-2012 The music still work... But thanks!!! It works now RE: Script Error 4.0 - Cruzore - 06-20-2012 Edited above post, it should work after that. RE: Script Error 4.0 - GoranGaming - 06-20-2012 It does RE: Script Error 4.0 - GoranGaming - 06-23-2012 Ok lol, I found a bug to the script. Every time a lever gets pulled to the right position, it adds 1 to the LocalVarInt "Levers", so, you could just pull a lever 6 times, and you would have solved the puzzle, I have a video showing you if you do not undeerstand. Can anyone tell me how to fix this? http://www.youtube.com/watch?v=L2cz1IP1Db8&feature=youtu.be Here is the script again, since I have changed a few things: ///////////////////// //BEGIN LEVER SCRIPT ///////////////////// void PullLever1(string &in asEntity, int alState) { if(alState == 1){ AddDebugMessage("Lever 1 is in the right position", false); AddLocalVarInt("Levers", 1); PlaySoundAtEntity("", "lever_mech_min_max", asEntity, 0.0f, false); }else if(alState == 0){ AddDebugMessage("Lever 1 is in the wrong position", false); }else if(alState == -1){ PlaySoundAtEntity("", "lever_mech_min_max", asEntity, 0.0f, false); } if(GetLocalVarInt("Levers") == 6){ 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); } } void PullLever2(string &in asEntity, int alState) { if(alState == -1){ AddDebugMessage("Lever 2 is in the right position", false); AddLocalVarInt("Levers", 1); }else if(alState == 0){ AddDebugMessage("Lever 2 is in the wrong position", false); }else if(alState == 1){ PlaySoundAtEntity("", "lever_mech_min_max", asEntity, 0.0f, false); } if(GetLocalVarInt("Levers") == 6){ 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); } } void PullLever3(string &in asEntity, int alState) { if(alState == -1){ AddDebugMessage("Lever 3 is in the right position", false); AddLocalVarInt("Levers", 1); }else if(alState == 0){ AddDebugMessage("Lever 3 is in the wrong position", false); }else if(alState == 1){ PlaySoundAtEntity("", "lever_mech_min_max", asEntity, 0.0f, false); } if(GetLocalVarInt("Levers") == 6){ 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); } } void PullLever4(string &in asEntity, int alState) { if(alState == 1){ AddDebugMessage("Lever 4 is in the right position", false); AddLocalVarInt("Levers", 1); }else if(alState == 0){ AddDebugMessage("Lever 4 is in the wrong position", false); }else if(alState == -1){ PlaySoundAtEntity("", "lever_mech_min_max", asEntity, 0.0f, false); } if(GetLocalVarInt("Levers") == 6){ 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); } } void PullLever5(string &in asEntity, int alState) { if(alState == 1){ AddDebugMessage("Lever 5 is in the right position", false); AddLocalVarInt("Levers", 1); }else if(alState == 0){ AddDebugMessage("Lever 5 is in the wrong position", false); }else if(alState == -1){ PlaySoundAtEntity("", "lever_mech_min_max", asEntity, 0.0f, false); } if(GetLocalVarInt("Levers") == 6){ 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); } } void PullLever6(string &in asEntity, int alState) { if(alState == -1){ AddDebugMessage("Lever 6 is in the right position", false); AddLocalVarInt("Levers", 1); }else if(alState == 0){ AddDebugMessage("Lever 6 is in the wrong position", false); }else if(alState == 1){ PlaySoundAtEntity("", "lever_mech_min_max", asEntity, 0.0f, false); } if(GetLocalVarInt("Levers") == 6){ 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); } } void TouchLeversAfterCompletion(string &in Timer) { SetEntityPlayerInteractCallback("lever_machine_lever01", "TouchSixLeversStuck", false); SetEntityPlayerInteractCallback("lever_machine_lever02", "TouchSixLeversStuck", false); SetEntityPlayerInteractCallback("lever_machine_lever03", "TouchSixLeversStuck", false); SetEntityPlayerInteractCallback("lever_machine_lever04", "TouchSixLeversStuck", false); SetEntityPlayerInteractCallback("lever_machine_lever05", "TouchSixLeversStuck", false); SetEntityPlayerInteractCallback("lever_machine_lever06", "TouchSixLeversStuck", false); } void TouchSixLeversStuck(string &in asEntity) { SetMessage("Messages", "TouchSixLeversStuck", 5); } ////////////////// //END LEVER SCRIPT ////////////////// 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); //END LEVER SCRIPT } RE: Script Error 4.0 - Cruzore - 06-23-2012 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. RE: Script Error 4.0 - GoranGaming - 06-23-2012 I tried this one, but it didnt work in the end with the if(GetLocalVarInt("lever1") == 1 && (GetLocalVarInt("lever2") == 1 But I'll try again |