Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scripts having effects in two levels
Ravenskull Offline
Junior Member

Posts: 18
Threads: 5
Joined: Nov 2011
Reputation: 0
#1
scripts having effects in two levels

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. Smile
05-06-2012, 04:52 PM
Find
Streetboat Offline
Posting Freak

Posts: 1,099
Threads: 40
Joined: Mar 2011
Reputation: 56
#2
RE: scripts having effects in two levels

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)
OnStart()
{
SetEntityConnectionStateChangeCallback("Lever", "LeverFunc");
}
void roomlever(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLeverStuckState("Lever", 1, true);
SetLeverInteractionDisablesStuck("Lever", true);
AddGlobalVarInt("LeverVar", 1);
}
}

(Second level .hps file)
OnEnter()
{
if (GetGlobalVarInt("LeverVar") == 1)
{
(Put whatever script you would want the lever to run in this area)
}
}


And there you have it!

[Image: signature-2.png]
(This post was last modified: 05-06-2012, 06:44 PM by Streetboat.)
05-06-2012, 06:42 PM
Find
Ravenskull Offline
Junior Member

Posts: 18
Threads: 5
Joined: Nov 2011
Reputation: 0
#3
RE: scripts having effects in two levels

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);

}
}
(This post was last modified: 05-07-2012, 04:55 PM by Ravenskull.)
05-07-2012, 04:33 PM
Find
Ravenskull Offline
Junior Member

Posts: 18
Threads: 5
Joined: Nov 2011
Reputation: 0
#4
RE: scripts having effects in two levels

okay, i´ve got it i just forgot the "void" before the "OnEnter" part
05-07-2012, 07:37 PM
Find
Streetboat Offline
Posting Freak

Posts: 1,099
Threads: 40
Joined: Mar 2011
Reputation: 56
#5
RE: scripts having effects in two levels

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! Smile

[Image: signature-2.png]
05-07-2012, 08:11 PM
Find




Users browsing this thread: 1 Guest(s)