User Tools

Site Tools


hpl2:tutorials:script:levers_and_secretshelfs

Link to this comparison view

Next revision
Previous revision
hpl2:tutorials:script:levers_and_secretshelfs [2011/07/14 01:34]
xtron created
hpl2:tutorials:script:levers_and_secretshelfs [2014/07/03 01:36] (current)
romulator
Line 1: Line 1:
 ====== Levers that opens secret shelfs ====== ====== Levers that opens secret shelfs ======
- 
  
 In this tutorial I (xtron) will show you! (the reader) how to make levers that opens secret bookshelfs!. In this tutorial I (xtron) will show you! (the reader) how to make levers that opens secret bookshelfs!.
- 
  
 ===== The Bookshelf ===== ===== The Bookshelf =====
- 
  
 First off you need to create a moveable bookshelf. First off you need to create a moveable bookshelf.
- 
  
 Go to Entities(7) > Gameplay > Look for "​shelf_secret_door_rot"​ and place it where ever you want it. Change it's name to your liking. Go to Entities(7) > Gameplay > Look for "​shelf_secret_door_rot"​ and place it where ever you want it. Change it's name to your liking.
- 
  
 secondly you need to create a script area that the shelf will rotate around. secondly you need to create a script area that the shelf will rotate around.
- 
  
 Go to Areas(8) > Select "​script"​ and create an area like so: Go to Areas(8) > Select "​script"​ and create an area like so:
  
 +[[http://​img6.imageshack.us/​img6/​4914/​shelf1.png|img6.imageshack.us/​img6/​4914/​shelf1.png]]
  
-[[http://img6.imageshack.us/​img6/4914/shelf1.png|img6.imageshack.us/​img6/4914/shelf1.png]]  +(If that link does not work, try this: [[http://puu.sh/9UrRK/721008bb1d.jpg|puu.sh/9UrRK/721008bb1d.jpg]])
- +
- +
-When you're done adding that area, name it anything for example: rotatearea.+
  
 +When you're done adding that area, name it anything for example: rotate.
  
 Then press on the bookshelf and go to Entity. The last text box named AngularOffsetArea,​ you'll need to type in the rotate area you Then press on the bookshelf and go to Entity. The last text box named AngularOffsetArea,​ you'll need to type in the rotate area you
- 
  
 just created like so: just created like so:
  
 +[[http://​img155.imageshack.us/​img155/​948/​shelf2.png|img155.imageshack.us/​img155/​948/​shelf2.png]]
  
-[[http://img155.imageshack.us/img155/948/shelf2.png|img155.imageshack.us/​img155/948/shelf2.png]]  +(If that link does not work, try this: [[http://puu.sh/9Us9N/ac50a930f0.jpg|puu.sh/9Us9N/ac50a930f0.jpg]])
  
 Now you're done with the bookshelf!. Let's setup the lever. Now you're done with the bookshelf!. Let's setup the lever.
- 
  
 ===== Adding the Lever ===== ===== Adding the Lever =====
- 
  
 You will be needing a Lever to make the Bookshelf open so go to You will be needing a Lever to make the Bookshelf open so go to
- 
  
 Entities > Gameplay > Look for lever_simple01. You can choose any of those levers. Change the Levers name to your liking. Entities > Gameplay > Look for lever_simple01. You can choose any of those levers. Change the Levers name to your liking.
- 
  
 The lever is now DONE!. Easy ayee?. Let's get working on the script then. The lever is now DONE!. Easy ayee?. Let's get working on the script then.
- 
  
 ===== The Script ===== ===== The Script =====
- 
  
 We will first fix the code that is needed in the void OnStart() area. We will first fix the code that is needed in the void OnStart() area.
  
- +<code cpp>void OnStart()
-<code cpp> +
-void OnStart()+
 { {
 SetEntityConnectionStateChangeCallback("​lever",​ "​func_shelf"​);​ SetEntityConnectionStateChangeCallback("​lever",​ "​func_shelf"​);​
 } }
 </​code>​ </​code>​
- 
  
 Change "​lever"​ to the name of your Lever you created in the previous part. Change "​lever"​ to the name of your Lever you created in the previous part.
- 
  
 Now we need to setup the "​move-the-bookshelf-when-lever-is-pressed"​ Now we need to setup the "​move-the-bookshelf-when-lever-is-pressed"​
- 
  
 Copy this code and insert it anywhere but void OnStart() Copy this code and insert it anywhere but void OnStart()
  
 +<code cpp>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>​
 +
 +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.
 +
 +This is how the complete script should look like:
 +
 +<code cpp>void OnStart()
 +{
 +SetEntityConnectionStateChangeCallback("​lever",​ "​func_shelf"​);​
 +}
  
-<code cpp> 
 void func_shelf(string &in asEntity, int alState) void func_shelf(string &in asEntity, int alState)
 { {
Line 84: Line 85:
 } }
 </​code>​ </​code>​
-Change "​shelf"​ to your shelfs name. 
  
 +===== More Than One Lever =====
  
-The SetEntityConnectionStateChangeCallback will execute SetMoveObjectState and PlaySoundAtEntity when the levers State turned to 1. The lever'​s ​starting position is always 0+Simply add another ​lever through the Level editor and change it'​s ​name to your liking.
  
 +Add this to void OnStart()
  
-1 = drag down+<code cpp> 
 +SetLocalVarInt("​Var1",​ 0);
  
 +SetEntityConnectionStateChangeCallback("​lever_1",​ "​func_shelf_1"​);​
 +</​code>​
  
--1 = drag up+change lever_1 to the second lever you added.
  
 +Add this code anyhere but void OnStart()
  
-I hope you find this tutorial usefull. Contact on FG forum if you want any specific tutorial or got any questions.+<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();​
 +     }
 +}
  
-Thanks for reading.+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>​
 +
 +1 = drag down
 +
 +-1 = drag up
 +
 +I hope you find this tutorial usefull. Contact on FG forum if you want any specific tutorial or got any questions.
 +
 +Thanks for reading.
  
 //created by xtron// //created by xtron//
  
hpl2/tutorials/script/levers_and_secretshelfs.1310607294.txt.gz · Last modified: 2011/07/14 01:34 by xtron