Both sides previous revision Previous revision Next revision | Previous revision | ||
hpl2:tutorials:script:levers_and_secretshelfs [2011/07/14 01:49] xtron |
hpl2:tutorials:script:levers_and_secretshelfs [2014/07/03 01:36] 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() | ||
Line 61: | Line 46: | ||
} | } | ||
</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) | <code cpp>void func_shelf(string &in asEntity, int alState) | ||
Line 82: | Line 63: | ||
} | } | ||
</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: | This is how the complete script should look like: | ||
- | |||
<code cpp>void OnStart() | <code cpp>void OnStart() | ||
Line 97: | Line 74: | ||
SetEntityConnectionStateChangeCallback("lever", "func_shelf"); | SetEntityConnectionStateChangeCallback("lever", "func_shelf"); | ||
} | } | ||
- | + | ||
- | + | ||
void func_shelf(string &in asEntity, int alState) | void func_shelf(string &in asEntity, int alState) | ||
{ | { | ||
Line 109: | Line 85: | ||
} | } | ||
</code> | </code> | ||
- | |||
===== More Than One Lever ===== | ===== More Than One Lever ===== | ||
- | |||
Simply add another lever through the Level editor and change it's name to your liking. | Simply add another lever through the Level editor and change it's name to your liking. | ||
- | |||
Add this to void OnStart() | Add this to void OnStart() | ||
- | |||
<code cpp> | <code cpp> | ||
- | |||
SetLocalVarInt("Var1", 0); | SetLocalVarInt("Var1", 0); | ||
- | + | ||
- | + | ||
SetEntityConnectionStateChangeCallback("lever_1", "func_shelf_1"); | SetEntityConnectionStateChangeCallback("lever_1", "func_shelf_1"); | ||
</code> | </code> | ||
- | |||
change lever_1 to the second lever you added. | change lever_1 to the second lever you added. | ||
- | |||
Add this code anyhere but void OnStart() | Add this code anyhere but void OnStart() | ||
- | |||
<code cpp>void func_shelf(string &in asEntity, int alState) | <code cpp>void func_shelf(string &in asEntity, int alState) | ||
Line 143: | Line 110: | ||
} | } | ||
} | } | ||
- | + | ||
- | + | ||
void func_shelf_1(string &in asEntity, int alState) | void func_shelf_1(string &in asEntity, int alState) | ||
{ | { | ||
Line 153: | Line 119: | ||
} | } | ||
} | } | ||
- | + | ||
- | + | ||
void func01() | void func01() | ||
{ | { | ||
Line 164: | Line 129: | ||
} | } | ||
</code> | </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. | 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. | When the count is 2 func01 gets executed and activates SetMoveObjectState and PlaySoundAtEntity. | ||
- | |||
The complete script should look like this: | The complete script should look like this: | ||
- | |||
<code cpp>void OnStart() | <code cpp>void OnStart() | ||
Line 181: | Line 142: | ||
SetEntityConnectionStateChangeCallback("lever_1", "func_shelf_1"); | SetEntityConnectionStateChangeCallback("lever_1", "func_shelf_1"); | ||
} | } | ||
- | + | ||
- | + | ||
void func_shelf(string &in asEntity, int alState) | void func_shelf(string &in asEntity, int alState) | ||
{ | { | ||
Line 191: | Line 151: | ||
} | } | ||
} | } | ||
- | + | ||
- | + | ||
void func_shelf_1(string &in asEntity, int alState) | void func_shelf_1(string &in asEntity, int alState) | ||
{ | { | ||
Line 201: | Line 160: | ||
} | } | ||
} | } | ||
- | + | ||
- | + | ||
void func01() | void func01() | ||
{ | { | ||
Line 212: | Line 170: | ||
} | } | ||
</code> | </code> | ||
- | |||
1 = drag down | 1 = drag down | ||
- | |||
-1 = drag up | -1 = drag up | ||
- | |||
I hope you find this tutorial usefull. Contact on FG forum if you want any specific tutorial or got any questions. | I hope you find this tutorial usefull. Contact on FG forum if you want any specific tutorial or got any questions. | ||
- | |||
Thanks for reading. | Thanks for reading. | ||
- | |||
//created by xtron// | //created by xtron// | ||