Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pull lever Combination lock [Help Needed]
Simpanra Offline
Senior Member

Posts: 314
Threads: 28
Joined: Mar 2011
Reputation: 0
#1
Pull lever Combination lock [Help Needed]

Ok, i have decided to make my next video tutorial on more advanced scripting, in particular; how to make a combination to open or do something (by combo i mean like 3, 2, 4, 1, by pulling levers or books)

Lets say i have four levers, each one is called lever1, lever2, lever3 and lever4. And i want them to unlock a door, lets call the door lockeddoor1.

Please can somebody make an example script and explain it for me? =) This will be really helpful as i can then make my next video tutorial to put on my thread ^_^ all credit will go to the ones who help me =)

thank you,

Edd,
05-02-2011, 10:00 AM
Find
Kyle Offline
Posting Freak

Posts: 911
Threads: 36
Joined: Sep 2010
Reputation: 7
#2
RE: Pull lever Combination lock [Help Needed]

It depends what you want to happen once the player does got the combination. Smile

05-02-2011, 11:11 AM
Find
Simpanra Offline
Senior Member

Posts: 314
Threads: 28
Joined: Mar 2011
Reputation: 0
#3
RE: Pull lever Combination lock [Help Needed]

preferably something cool like a stack of shelves swivelling on an axis to reveal a door, ^_^
05-02-2011, 11:16 AM
Find
Kyle Offline
Posting Freak

Posts: 911
Threads: 36
Joined: Sep 2010
Reputation: 7
#4
RE: Pull lever Combination lock [Help Needed]

(05-02-2011, 11:16 AM)Simpanra Wrote: preferably something cool like a stack of shelves swivelling on an axis to reveal a door, ^_^

Hmm... I never did something like that before... But I'll try.

void OnStart()
{
SetLocalVarInt("Lev", 1);
SetEntityConnectionStateChangeCallback("lever_1", "L1");
SetEntityConnectionStateChangeCallback("lever_2", "L2");
SetEntityConnectionStateChangeCallback("lever_3", "L3");
SetEntityConnectionStateChangeCallback("lever_4", "L4");
}
void Open()
{
[Insert what you want to happen here]
}
void L1(string &in asEntity, int alState)
{
if (alState == 1)
{
if (GetLocalVarInt("Lev") == 3)
{
SetLocalVarInt("Lev", 4);
SetEntityInteractionDisabled("lever_1", true);
return;
}
else if (GetLocalVarInt("Lev") != 3)
{
SetLocalVarInt("Lev", 1);
for (int i = 1; i > 0 && i < 5; i++)
{
SetEntityInteractionDisabled("lever_"+i, false);
}
return;
}
}
}
void L2(string &in asEntity, int alState)
{
if (alState == 1)
{
if (GetLocalVarInt("Lev") == 2)
{
SetLocalVarInt("Lev", 3);
SetEntityInteractionDisabled("lever_2", true);
return;
}
else if (GetLocalVarInt("Lev") != 2)
{
SetLocalVarInt("Lev", 1);
for (int i = 1; i > 0 && i < 5; i++)
{
SetEntityInteractionDisabled("lever_"+i, false);
}
return;
}
}
}
void L3(string &in asEntity, int alState)
{
if (alState == 1)
{
if (GetLocalVarInt("Lev") == 4)
{
SetLocalVarInt("Lev", 5);
SetEntityInteractionDisabled("lever_3", true);
Open();
return;
}
else if (GetLocalVarInt("Lev") != 4)
{
SetLocalVarInt("Lev", 1);
for (int i = 1; i > 0 && i < 5; i++)
{
SetEntityInteractionDisabled("lever_"+i, false);
}
return;
}
}
}
void L4(string &in asEntity, int alState)
{
if (alState == 1)
{
if (GetLocalVarInt("Lev") == 1)
{
SetLocalVarInt("Lev", 2);
SetEntityInteractionDisabled("lever_4", true);
return;
}
else if (GetLocalVarInt("Lev") != 1)
{
SetLocalVarInt("Lev", 1);
for (int i = 1; i > 0 && i < 5; i++)
{
SetEntityInteractionDisabled("lever_"+i, false);
}
return;
}
}
}

Ask any questions on how to do it, except now I got to go to school... :/

Also, to quickly say, I would indent it all but it doesn't really work too well on the forums when I post stuff.

(This post was last modified: 05-02-2011, 11:57 AM by Kyle.)
05-02-2011, 11:39 AM
Find
Simpanra Offline
Senior Member

Posts: 314
Threads: 28
Joined: Mar 2011
Reputation: 0
#5
RE: Pull lever Combination lock [Help Needed]

0_0 *tumbleweed tumbles past* well....that looks complicated enough to work.....two questions....number one, when you say "insert what you want to happen here" i have no idea how to make a shelves entity rotate on the X axis...and question two...could you explain the script for me? xDDD Im sorry to be so nooby but i need to understand whats happening so i can explain it in my video =)

Thanks man, have a good day at school too =)
05-02-2011, 11:58 AM
Find
Kyle Offline
Posting Freak

Posts: 911
Threads: 36
Joined: Sep 2010
Reputation: 7
#6
RE: Pull lever Combination lock [Help Needed]

I must say thanks. Okay, "SetLocalVarInt("Lev", 1);" sets a local integer named "Lev" that's used as a variable representing 1 as the amount of the variable at the time before it's changed(in the scope(usable in the whole script) of the script). The "SetEntityConnectionStateChangeCallback" is used when a lever, in this case "lever_1", changes state, 1 for down, 0 for middle, -1 for top. So if the lever is pulled up, nothing will happen, but if it's pulled down, then stuff does happens. In the function "L1", it checks to see if the "alState", or which way it's being pulled, and also checks if the local integer variable equals what it asks. So if the local integer variable currently equals 1, and you pull lever_1 down, then the "else if (GetLocalVarInt("Lev") != 3)" checks to see if the local integer variable does NOT equal 3. Since it equals 1, it sets all the levers active again so they can be pulled again in the correct order. So if the player pulls down the correct lever, it sets the local integer variable to the next number so they can pull the next lever. And it also sets the lever to not be able to be interacted with which could cause the player to screw up the combination by accidently pulling it twice, having to restart the combination. Big Grin

Alright, got to go, bye.

Also I don't really know how to make the shelves move on it's axis because I never tried. No time, got to go. :/

(This post was last modified: 05-02-2011, 12:13 PM by Kyle.)
05-02-2011, 12:11 PM
Find
Roenlond Offline
Senior Member

Posts: 331
Threads: 3
Joined: Apr 2011
Reputation: 0
#7
RE: Pull lever Combination lock [Help Needed]

void RotatePropToSpeed(string& asName, float afAcc, float afGoalSpeed, float afAxisX, float afAxisY, float afAxisZ, bool abResetSpeed, string& asOffsetArea);

Rotates the prop up to a set speed.

asName - internal name
afAcc - acceleration
afGoalSpeed - desired speed
afAxisX - rotation around X axis
afAxisY - rotation around Y axis
afAxisZ - rotation around Z axis
abResetSpeed - determines whether the speed is resetted after goal speed is reached
asOffsetArea - the area to rotate around, if ””, then the center of the body is used

That is most likely the function to use to rotate it.
05-02-2011, 12:22 PM
Find
Exostalker Offline
Member

Posts: 204
Threads: 10
Joined: Aug 2010
Reputation: 3
#8
RE: Pull lever Combination lock [Help Needed]

Shelf rotate you say?

This is what I use, so that after pushing the lever, shelf would rotate:

ConnectEntities("shelf_connection", "secret_lever", "secret_shelf", false, 1, "CreateDust");

05-02-2011, 02:34 PM
Find




Users browsing this thread: 1 Guest(s)