User Tools

Site Tools


hpl2:tutorials:script:levers_and_secretshelfs

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
hpl2:tutorials:script:levers_and_secretshelfs [2011/07/14 01:34]
xtron created
hpl2:tutorials:script:levers_and_secretshelfs [2011/07/14 01:49]
xtron
Line 56: Line 56:
  
  
-<code cpp> +<code cpp>void OnStart()
-void OnStart()+
 { {
 SetEntityConnectionStateChangeCallback("​lever",​ "​func_shelf"​);​ SetEntityConnectionStateChangeCallback("​lever",​ "​func_shelf"​);​
Line 73: Line 72:
  
  
-<code cpp> +<code cpp>void func_shelf(string &in asEntity, int alState)
-void func_shelf(string &in asEntity, int alState)+
 { {
      if (alState == 1)      if (alState == 1)
Line 84: Line 82:
 } }
 </​code>​ </​code>​
 +
 +
 Change "​shelf"​ to your shelfs name. Change "​shelf"​ to your shelfs name.
  
  
-The SetEntityConnectionStateChangeCallback will execute SetMoveObjectState and PlaySoundAtEntity when the levers State turned to 1. The lever'​s starting position is always 0. +The SetEntityConnectionStateChangeCallback will execute SetMoveObjectState and PlaySoundAtEntity when the levers State turned to 1. The lever'​s starting position is always 0. 
 + 
 + 
 +This is how the complete script should look like: 
 + 
 + 
 +<code cpp>void OnStart() 
 +
 +SetEntityConnectionStateChangeCallback("​lever",​ "​func_shelf"​);​ 
 +
 +  
 +  
 +void func_shelf(string &in asEntity, int alState) 
 +
 +     if (alState == 1) 
 +     { 
 +     ​SetMoveObjectState("​shelf",​1.0f);​ 
 +     ​PlaySoundAtEntity("",​ "​quest_completed.snt",​ "​shelf_move_1",​ 0, false); 
 +          return; 
 +     } 
 +
 +</​code>​ 
 + 
 + 
 +===== More Than One Lever ===== 
 + 
 + 
 +Simply add another lever through the Level editor and change it's name to your liking. 
 + 
 + 
 +Add this to void OnStart() 
 + 
 + 
 +<code cpp> 
 +  
 +SetLocalVarInt("​Var1",​ 0); 
 +  
 +  
 +SetEntityConnectionStateChangeCallback("​lever_1",​ "​func_shelf_1"​);​ 
 +</​code>​ 
 + 
 + 
 +change lever_1 to the second lever you added. 
 + 
 + 
 +Add this code anyhere but void OnStart() 
 + 
 + 
 +<code cpp>void func_shelf(string &in asEntity, int alState) 
 +
 +     if (alState == 1) 
 +     { 
 +     ​AddLocalVarInt("​Var1",​ 1); 
 +     ​func01();​ 
 +     } 
 +
 +  
 +  
 +void func_shelf_1(string &in asEntity, int alState) 
 +
 +     if (alState == 1) 
 +     { 
 +     ​AddLocalVarInt("​Var1",​ 1); 
 +     ​func01();​ 
 +     } 
 +
 +  
 +  
 +void func01() 
 +
 +if(GetLocalVarInt("​Var1"​) == 2) 
 +    { 
 +    SetMoveObjectState("​shelf",​1.0f);​ 
 +    PlaySoundAtEntity("",​ "​quest_completed.snt",​ "​shelf",​ 0, false); 
 +    } 
 +
 +</​code>​ 
 + 
 + 
 +Var1 will start at the count 0 and everytime you drag a lever the count raises by 1 so when you draged both of the levers the count is at 2. 
 + 
 + 
 +When the count is 2 func01 gets executed and activates SetMoveObjectState and PlaySoundAtEntity. 
 + 
 + 
 +The complete script should look like this: 
 + 
 + 
 +<code cpp>void OnStart() 
 +
 +SetLocalVarInt("​Var1",​ 0); 
 +SetEntityConnectionStateChangeCallback("​lever",​ "​func_shelf"​);​ 
 +SetEntityConnectionStateChangeCallback("​lever_1",​ "​func_shelf_1"​);​ 
 +
 +  
 +  
 +void func_shelf(string &in asEntity, int alState) 
 +
 +     if (alState == 1) 
 +     { 
 +     ​AddLocalVarInt("​Var1",​ 1); 
 +     ​func01();​ 
 +     } 
 +
 +  
 +  
 +void func_shelf_1(string &in asEntity, int alState) 
 +
 +     if (alState == 1) 
 +     { 
 +     ​AddLocalVarInt("​Var1",​ 1); 
 +     ​func01();​ 
 +     } 
 +
 +  
 +  
 +void func01() 
 +
 +if(GetLocalVarInt("​Var1"​) == 2) 
 +    { 
 +    SetMoveObjectState("​shelf",​1.0f);​ 
 +    PlaySoundAtEntity("",​ "​quest_completed.snt",​ "​shelf",​ 0, false); 
 +    } 
 +
 +</​code>​
  
  
hpl2/tutorials/script/levers_and_secretshelfs.txt · Last modified: 2014/07/03 01:36 by romulator