scripts having effects in two levels - 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: scripts having effects in two levels (/thread-15292.html) |
scripts having effects in two levels - Ravenskull - 05-06-2012 Hey, I´ve a quick question. How is it possible to make a script having effect in another lvl. For example if the player pulls a lever in the first level and in another level a pointlight, or sound is set active. Thanks for your help. RE: scripts having effects in two levels - Streetboat - 05-06-2012 You gotta use Global Variables for that. What you do is, when you pull the lever in the first level, it calls the function 'SetGlobalVarInt', and then in the other level, in the 'OnEnter' section of your .hps file, you'll have an if statement stating that 'if (GetGlobalVarInt("name of var") == 1)' then it runs the script changing the state of whatever you wanted it to do. Here's what it would look like as an example. Quote:(First lever script) And there you have it! RE: scripts having effects in two levels - Ravenskull - 05-07-2012 Hey, thank you very much for your quick and precise answer! Hey, there´s still a prolem. The error message says theres a expected identifier missing or s.th. like that. Would you be so kind to check my script? FIRST LEVEL : void OnStart() { AddEntityCollideCallback("Player", "lights", "SuddenLight", true, 1); SetLocalVarInt("Var1", 0); SetEntityConnectionStateChangeCallback("lever", "func_shelf"); SetEntityConnectionStateChangeCallback("lever_1", "func_shelf1"); SetEntityConnectionStateChangeCallback("lever_2", "func_shelf2"); SetEntityConnectionStateChangeCallback("lever_3", "func_shelf3"); SetEntityConnectionStateChangeCallback("lever_4", "func_shelf4"); } void SuddenLight(string &in asParent, string &in asChild, int alState) { SetLightVisible("BoxLight_2", false); PlaySoundAtEntity("", "enemy_hallucination_disappear.snt", "Player", 0, false); } void func_shelf(string &in asEntity, int alState) { if (alState == 1) { AddLocalVarInt("Var1", 1); func01(); } } void func_shelf1(string &in asEntity, int alState) { if (alState == 1) { AddLocalVarInt("Var1", 1); func01(); } } void func_shelf2(string &in asEntity, int alState) { if (alState == 1) { AddLocalVarInt("Var1", 1); func01(); } } void func_shelf3(string &in asEntity, int alState) { if (alState == 1) { AddLocalVarInt("Var1", 1); func01(); } } void func_shelf4(string &in asEntity, int alState) { if (alState == 1) { AddLocalVarInt("Var1", 1); func01(); } } void func01() { if(GetLocalVarInt("Var1") == 5) { PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false); AddGlobalVarInt("LeverVar", 1); GiveSanityDamage(15.0f, true); SetEntityActive("servant_grunt_1", true); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_1", 2, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_2", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_3", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_4", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_5", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_6", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_7", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_8", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_9", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_10", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_11", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_12", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_13", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_14", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_15", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_16", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_17", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_18", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_19", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_20", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_21", 0, ""); } } SECOND LEVEL : void OnStart() { AddEntityCollideCallback("Player", "PlayerCollide", "MonsterFunction", true, 1); AddUseItemCallback("", "crowbar_1", "prison_x", "UsedCrowbarOnDoor", true); AddEntityCollideCallback("crowbar_joint_1", "ScriptArea_1", "CollideAreaBreakDoor", true, 1); } void MonsterFunction(string &in asParent, string &in asChild, int alState) { PlaySoundAtEntity("", "guardian_activated.snt", "Player", 0, false); PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false); SetEntityActive("servant_grunt_1", true); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_1", 2, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_2", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_3", 0, ""); AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_4", 0, ""); GiveSanityDamage(15.0f, true); SetEntityActive("boxlight_1", true); } void UsedCrowbarOnDoor(string &in asItem, string &in asEntity) { AddTimer("", 0.2, "TimerSwitchShovel"); RemoveItem("crowbar_1"); } void TimerSwitchShovel(string &in asTimer) { PlaySoundAtEntity("","puzzle_place_jar.snt", "", 0, false); SetEntityActive("crowbar_joint_1", true); } void CollideAreaBreakDoor(string &in asParent, string &in asChild, int alState) { AddPlayerSanity(25); PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false); SetMoveObjectState("prison_x", 1); PlaySoundAtEntity("","break_wood_metal", "AreaBreakEffect", 0, false); CreateParticleSystemAtEntity("", "ps_hit_wood", "AreaBreakEffect", false); SetEntityActive("crowbar_joint_1", false); SetEntityActive("prison_x", false); } OnEnter() { if (GetGlobalVarInt("LeverVar") == 5); { SetEntityActive("test1", true); } } RE: scripts having effects in two levels - Ravenskull - 05-07-2012 okay, i´ve got it i just forgot the "void" before the "OnEnter" part RE: scripts having effects in two levels - Streetboat - 05-07-2012 Glad to hear it worked out for you! I approve of your decision to use levers that change things in separate levels- a mechanic that is often forgotten about! Good luck! |