| 
		
	
		| Athom   Junior Member
 
 Posts: 32
 Threads: 6
 Joined: Jul 2012
 Reputation: 
1
 | 
			| Combination Lock Using Levers Code? 
 
				Hey everybody! I want to make a combination lock with three levers. The levers are named lever_1, lever_2, and lever_3. I want it to be arranged as 231. so, lever_2, lever_3, lever_1 I need somebody else to write a sample code for this as i am a huge noob. When the correct combination is put in, i want a cabinet to slide/spin to reveal a secret wall with a key inside. If anybody can get back to me with a sample code, i will be eternally grateful! 
 Thank you!
 
 |  |  
	| 07-16-2012, 10:36 AM |  |  
	
		| Traggey   is mildly amused
 
 Posts: 3,257
 Threads: 74
 Joined: Feb 2012
 Reputation: 
185
 | 
			| RE: Combination Lock Using Levers Code? 
 
				Wrong forum section, this goes to development support, not tech support, moved.
			 |  |  
	| 07-16-2012, 12:06 PM |  |  
	
		| Ongka   Member
 
 Posts: 225
 Threads: 3
 Joined: Nov 2010
 Reputation: 
20
 | 
			| RE: Combination Lock Using Levers Code? 
 
				Which combination should unlock the cabinet?231 is the same as 123. The only difference is the name of levers.
 
 |  |  
	| 07-16-2012, 01:52 PM |  |  
	
		| Athom   Junior Member
 
 Posts: 32
 Threads: 6
 Joined: Jul 2012
 Reputation: 
1
 | 
			| RE: Combination Lock Using Levers Code? 
 
				 (07-16-2012, 01:52 PM)Ongka Wrote:  Which combination should unlock the cabinet?231 is the same as 123. The only difference is the name of levers.
 I want them
 
 
im sorry. I didnt know i should post in that section. I want 3 levers in a room and when pulled in this order (middle, right, left) a secret bookcase will open. Can anybody help me with this?
			 
 
				
(This post was last modified: 07-16-2012, 06:28 PM by Athom.)
 |  |  
	| 07-16-2012, 06:27 PM |  |  
	
		| Your Computer   SCAN ME!
 
 Posts: 3,456
 Threads: 32
 Joined: Jul 2011
 Reputation: 
235
 | 
			| RE: Combination Lock Using Levers Code? 
 
				At first i was going to explain it all, but decided just to post some code: const string[] secret_door_lever_positions ={"secret_door_first_lever",
 "secret_door_second_lever",
 "secret_door_third_lever"};
 
 void OnStart ()
 {
 SetEntityConnectionStateChangeCallback("lever_left", "SecretDoorLevers");
 SetEntityConnectionStateChangeCallback("lever_middle", "SecretDoorLevers");
 SetEntityConnectionStateChangeCallback("lever_right", "SecretDoorLevers");
 
 ClearSecretDoorLevers();
 ResetSecretDoorLevers();
 }
 
 void ClearSecretDoorLevers()
 {
 SetLocalVarString(secret_door_lever_positions[0], "");
 SetLocalVarString(secret_door_lever_positions[1], "");
 SetLocalVarString(secret_door_lever_positions[2], "");
 }
 
 void ResetSecretDoorLevers()
 {
 SetLeverStuckState("lever_left", 0, true);
 SetLeverStuckState("lever_middle", 0, true);
 SetLeverStuckState("lever_right", 0, true);
 }
 
 void SecretDoorLevers(string &in entity, int state)
 {
 SetLeverStuckState(entity, state, false);
 
 for (int i = 0; i < secret_door_lever_positions.length(); ++i)
 {
 if (GetLocalVarString(secret_door_lever_positions[i]) == "")
 {
 SetLocalVarString(secret_door_lever_positions[i], entity);
 break;
 }
 }
 
 CheckSecretDoorLeversOrder();
 }
 
 void CheckSecretDoorLeversOrder()
 {
 if (GetLocalVarString(secret_door_lever_positions[0]) == "lever_middle"
 && GetLocalVarString(secret_door_lever_positions[1]) == "lever_right"
 && GetLocalVarString(secret_door_lever_positions[2]) == "lever_left")
 {
 CompleteSecretDoorLeversPuzzle();
 }
 
 else if (GetLocalVarString(secret_door_lever_positions[0]) != ""
 && GetLocalVarString(secret_door_lever_positions[1]) != ""
 && GetLocalVarString(secret_door_lever_positions[2]) != "")
 {
 ClearSecretDoorLevers();
 ResetSecretDoorLevers();
 }
 }
 
 void CompleteSecretDoorLeversPuzzle()
 {
 AddDebugMessage("Secret door puzzle complete!", false);
 Print("Secret door puzzle complete!");
 // Open secret door
 }
 
Note, you'll have to change the names of the levers to "lever_middle", "lever_left" and "lever_right". Since you didn't specify which state you want the levers to be pulled at, pulling them in either direction should work.
			
 
				
(This post was last modified: 07-16-2012, 11:26 PM by Your Computer.)
 |  |  
	| 07-16-2012, 11:19 PM |  |  
	
		| Ongka   Member
 
 Posts: 225
 Threads: 3
 Joined: Nov 2010
 Reputation: 
20
 | 
			| RE: Combination Lock Using Levers Code? 
 
				It might look pretty confusing for a beginner, because of the const string and all that.But anyway, nice work there buddy!
 
 |  |  
	| 07-17-2012, 12:07 AM |  |  
	
		| Athom   Junior Member
 
 Posts: 32
 Threads: 6
 Joined: Jul 2012
 Reputation: 
1
 | 
			| RE: Combination Lock Using Levers Code? 
 
				I got a friend to help me with the script for it. Here it is for anyone who wants to use it! 
void LeverPulled(string &in asEntity, int alState) 
{ 
if(GetLocalVarInt("Sequence") == 0 && asEntity == "lever_2") 
{ 
AddLocalVarInt("Sequence", 1); 
SetLeverStuckState(asEntity, alState, true); 
PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false); 
} 
if(GetLocalVarInt("Sequence") == 1 && asEntity == "lever_1") 
{ 
AddLocalVarInt("Sequence", 1); 
SetLeverStuckState(asEntity, alState, true); 
PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false); 
} 
if(GetLocalVarInt("Sequence") == 2 && asEntity == "lever_3") 
{ 
AddLocalVarInt("Sequence", 1); 
SetLeverStuckState(asEntity, alState, true); 
SetMoveObjectState("shelf_secret_door_1", 1); 
PlaySoundAtEntity("", "scrape_wood_heavy.snt", "Player", 0, false); 
PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false); 
StopSound("tunnel", 1.0f); 
GiveSanityBoostsmall(); 
}
 
There you go. I think it is a bit simpler than the above script! ENJOY! 
Small edit, fixing "tunnel" sound lasting for a LONG time!
 
  (07-18-2012, 09:20 AM)Athom Wrote:  I got a friend to help me with the script for it. Here it is for anyone who wants to use it!
 
 
 void LeverPulled(string &in asEntity, int alState)
 {
 if(GetLocalVarInt("Sequence") == 0 && asEntity == "lever_2")
 {
 AddLocalVarInt("Sequence", 1);
 SetLeverStuckState(asEntity, alState, true);
 PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false);
 }
 if(GetLocalVarInt("Sequence") == 1 && asEntity == "lever_1")
 {
 AddLocalVarInt("Sequence", 1);
 SetLeverStuckState(asEntity, alState, true);
 PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false);
 }
 if(GetLocalVarInt("Sequence") == 2 && asEntity == "lever_3")
 {
 AddLocalVarInt("Sequence", 1);
 SetLeverStuckState(asEntity, alState, true);
 SetMoveObjectState("shelf_secret_door_1", 1);
 PlaySoundAtEntity("", "scrape_wood_heavy.snt", "Player", 0, false);
 PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false);
 StopSound("tunnel", 1.0f);
 GiveSanityBoostsmall();
 }
 
 There you go. I think it is a bit simpler than the above script! ENJOY!
 Small edit, fixing "tunnel" sound lasting for a LONG time!
 I give thanks for writing this script to andyrockin123 and Obliviator27! I love you guys! You RULE!
			
 
				
(This post was last modified: 07-18-2012, 09:57 AM by Athom.)
 |  |  
	| 07-18-2012, 09:20 AM |  |  |