<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.frictionalgames.com/page?action=history&amp;feed=atom&amp;title=Hpl2%3ATutorials%3Ascript%3Alevers_and_secretshelfs</id>
	<title>Hpl2:Tutorials:script:levers and secretshelfs - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.frictionalgames.com/page?action=history&amp;feed=atom&amp;title=Hpl2%3ATutorials%3Ascript%3Alevers_and_secretshelfs"/>
	<link rel="alternate" type="text/html" href="https://wiki.frictionalgames.com/page?title=Hpl2:Tutorials:script:levers_and_secretshelfs&amp;action=history"/>
	<updated>2026-05-14T04:47:11Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://wiki.frictionalgames.com/page?title=Hpl2:Tutorials:script:levers_and_secretshelfs&amp;diff=846&amp;oldid=prev</id>
		<title>Maintenance script: Upload from wiki</title>
		<link rel="alternate" type="text/html" href="https://wiki.frictionalgames.com/page?title=Hpl2:Tutorials:script:levers_and_secretshelfs&amp;diff=846&amp;oldid=prev"/>
		<updated>2020-07-09T13:48:46Z</updated>

		<summary type="html">&lt;p&gt;Upload from wiki&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Levers that opens secret shelfs =&lt;br /&gt;
&lt;br /&gt;
In this tutorial I (xtron) will show you! (the reader) how to make levers that opens secret bookshelfs!.&lt;br /&gt;
&lt;br /&gt;
== The Bookshelf ==&lt;br /&gt;
&lt;br /&gt;
First off you need to create a moveable bookshelf.&lt;br /&gt;
&lt;br /&gt;
Go to Entities(7) &amp;gt; Gameplay &amp;gt; Look for &amp;quot;shelf_secret_door_rot&amp;quot; and place it where ever you want it. Change it's name to your liking.&lt;br /&gt;
&lt;br /&gt;
secondly you need to create a script area that the shelf will rotate around.&lt;br /&gt;
&lt;br /&gt;
Go to Areas(8) &amp;gt; Select &amp;quot;script&amp;quot; and create an area like so:&lt;br /&gt;
&lt;br /&gt;
[http://img6.imageshack.us/img6/4914/shelf1.png img6.imageshack.us/img6/4914/shelf1.png]&lt;br /&gt;
&lt;br /&gt;
(If that link does not work, try this: [http://puu.sh/9UrRK/721008bb1d.jpg puu.sh/9UrRK/721008bb1d.jpg])&lt;br /&gt;
&lt;br /&gt;
When you're done adding that area, name it anything for example: rotate.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
&lt;br /&gt;
just created like so:&lt;br /&gt;
&lt;br /&gt;
[http://img155.imageshack.us/img155/948/shelf2.png img155.imageshack.us/img155/948/shelf2.png]&lt;br /&gt;
&lt;br /&gt;
(If that link does not work, try this: [http://puu.sh/9Us9N/ac50a930f0.jpg puu.sh/9Us9N/ac50a930f0.jpg])&lt;br /&gt;
&lt;br /&gt;
Now you're done with the bookshelf!. Let's setup the lever.&lt;br /&gt;
&lt;br /&gt;
== Adding the Lever ==&lt;br /&gt;
&lt;br /&gt;
You will be needing a Lever to make the Bookshelf open so go to&lt;br /&gt;
&lt;br /&gt;
Entities &amp;gt; Gameplay &amp;gt; Look for lever_simple01. You can choose any of those levers. Change the Levers name to your liking.&lt;br /&gt;
&lt;br /&gt;
The lever is now DONE!. Easy ayee?. Let's get working on the script then.&lt;br /&gt;
&lt;br /&gt;
== The Script ==&lt;br /&gt;
&lt;br /&gt;
We will first fix the code that is needed in the void OnStart() area.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;void OnStart()&lt;br /&gt;
{&lt;br /&gt;
SetEntityConnectionStateChangeCallback(&amp;quot;lever&amp;quot;, &amp;quot;func_shelf&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change &amp;quot;lever&amp;quot; to the name of your Lever you created in the previous part.&lt;br /&gt;
&lt;br /&gt;
Now we need to setup the &amp;quot;move-the-bookshelf-when-lever-is-pressed&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Copy this code and insert it anywhere but void OnStart()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;void func_shelf(string &amp;amp;in asEntity, int alState)&lt;br /&gt;
{&lt;br /&gt;
     if (alState == 1)&lt;br /&gt;
     {&lt;br /&gt;
     SetMoveObjectState(&amp;quot;shelf&amp;quot;,1.0f);&lt;br /&gt;
     PlaySoundAtEntity(&amp;quot;&amp;quot;, &amp;quot;quest_completed.snt&amp;quot;, &amp;quot;shelf_move_1&amp;quot;, 0, false);&lt;br /&gt;
          return;&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change &amp;quot;shelf&amp;quot; to your shelfs name.&lt;br /&gt;
&lt;br /&gt;
The SetEntityConnectionStateChangeCallback will execute SetMoveObjectState and PlaySoundAtEntity when the levers State turned to 1. The lever's starting position is always 0.&lt;br /&gt;
&lt;br /&gt;
This is how the complete script should look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;void OnStart()&lt;br /&gt;
{&lt;br /&gt;
SetEntityConnectionStateChangeCallback(&amp;quot;lever&amp;quot;, &amp;quot;func_shelf&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void func_shelf(string &amp;amp;in asEntity, int alState)&lt;br /&gt;
{&lt;br /&gt;
     if (alState == 1)&lt;br /&gt;
     {&lt;br /&gt;
     SetMoveObjectState(&amp;quot;shelf&amp;quot;,1.0f);&lt;br /&gt;
     PlaySoundAtEntity(&amp;quot;&amp;quot;, &amp;quot;quest_completed.snt&amp;quot;, &amp;quot;shelf_move_1&amp;quot;, 0, false);&lt;br /&gt;
          return;&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== More Than One Lever ==&lt;br /&gt;
&lt;br /&gt;
Simply add another lever through the Level editor and change it's name to your liking.&lt;br /&gt;
&lt;br /&gt;
Add this to void OnStart()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SetLocalVarInt(&amp;quot;Var1&amp;quot;, 0);&lt;br /&gt;
&lt;br /&gt;
SetEntityConnectionStateChangeCallback(&amp;quot;lever_1&amp;quot;, &amp;quot;func_shelf_1&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
change lever_1 to the second lever you added.&lt;br /&gt;
&lt;br /&gt;
Add this code anyhere but void OnStart()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;void func_shelf(string &amp;amp;in asEntity, int alState)&lt;br /&gt;
{&lt;br /&gt;
     if (alState == 1)&lt;br /&gt;
     {&lt;br /&gt;
     AddLocalVarInt(&amp;quot;Var1&amp;quot;, 1);&lt;br /&gt;
     func01();&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void func_shelf_1(string &amp;amp;in asEntity, int alState)&lt;br /&gt;
{&lt;br /&gt;
     if (alState == 1)&lt;br /&gt;
     {&lt;br /&gt;
     AddLocalVarInt(&amp;quot;Var1&amp;quot;, 1);&lt;br /&gt;
     func01();&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void func01()&lt;br /&gt;
{&lt;br /&gt;
if(GetLocalVarInt(&amp;quot;Var1&amp;quot;) == 2)&lt;br /&gt;
    {&lt;br /&gt;
    SetMoveObjectState(&amp;quot;shelf&amp;quot;,1.0f);&lt;br /&gt;
    PlaySoundAtEntity(&amp;quot;&amp;quot;, &amp;quot;quest_completed.snt&amp;quot;, &amp;quot;shelf&amp;quot;, 0, false);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
When the count is 2 func01 gets executed and activates SetMoveObjectState and PlaySoundAtEntity.&lt;br /&gt;
&lt;br /&gt;
The complete script should look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;void OnStart()&lt;br /&gt;
{&lt;br /&gt;
SetLocalVarInt(&amp;quot;Var1&amp;quot;, 0);&lt;br /&gt;
SetEntityConnectionStateChangeCallback(&amp;quot;lever&amp;quot;, &amp;quot;func_shelf&amp;quot;);&lt;br /&gt;
SetEntityConnectionStateChangeCallback(&amp;quot;lever_1&amp;quot;, &amp;quot;func_shelf_1&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void func_shelf(string &amp;amp;in asEntity, int alState)&lt;br /&gt;
{&lt;br /&gt;
     if (alState == 1)&lt;br /&gt;
     {&lt;br /&gt;
     AddLocalVarInt(&amp;quot;Var1&amp;quot;, 1);&lt;br /&gt;
     func01();&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void func_shelf_1(string &amp;amp;in asEntity, int alState)&lt;br /&gt;
{&lt;br /&gt;
     if (alState == 1)&lt;br /&gt;
     {&lt;br /&gt;
     AddLocalVarInt(&amp;quot;Var1&amp;quot;, 1);&lt;br /&gt;
     func01();&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void func01()&lt;br /&gt;
{&lt;br /&gt;
if(GetLocalVarInt(&amp;quot;Var1&amp;quot;) == 2)&lt;br /&gt;
    {&lt;br /&gt;
    SetMoveObjectState(&amp;quot;shelf&amp;quot;,1.0f);&lt;br /&gt;
    PlaySoundAtEntity(&amp;quot;&amp;quot;, &amp;quot;quest_completed.snt&amp;quot;, &amp;quot;shelf&amp;quot;, 0, false);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1 = drag down&lt;br /&gt;
&lt;br /&gt;
-1 = drag up&lt;br /&gt;
&lt;br /&gt;
I hope you find this tutorial usefull. Contact on FG forum if you want any specific tutorial or got any questions.&lt;br /&gt;
&lt;br /&gt;
Thanks for reading.&lt;br /&gt;
&lt;br /&gt;
''created by xtron''&lt;/div&gt;</summary>
		<author><name>Maintenance script</name></author>
		
	</entry>
</feed>