Jump to content
Sign in to follow this  
Undeceived

How to check if player tries to open a locked door

Recommended Posts

I closed three doors of a house by putting a game logic in top of it with this in the init line:

((nearestobjects [this, ["house_f"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true];  
((nearestobjects [this, ["house_f"], 5]) select 0) setVariable ['bis_disabled_Door_2',1,true]; 
((nearestobjects [this, ["house_f"], 5]) select 0) setVariable ['bis_disabled_Door_3',1,true];

Now when the player tries to open one of these, it will show the "locked door animation" (the door kind of shakes a bit, but stays closed).

But additionally I want to make the player say something like: "Damn! The door is locked!" How can I do that?

What I managed to achieve is to fire a trigger, when the animation of a non-locked door is played.

This is how you do it:

1. Don't lock the door with the code above

2. Put a game logic on top of the house and put this in its init:

house = position this nearestObject IDofthehouse

3. Make a trigger with this code in the condition:

((house animationPhase 'door_1_rot') == 1)

4. Put whatever you want to happen in the activation field of this trigger

This will make happen whatever you want, if you as the player open the door 1.

However this won't work for doors which were closed with the code at the top of this post... :mad: It seems that this closed door animation is not really an animation which can fulfill the trigger condition. Or it is but the door name is now different than door_1_rot? No idea...

Any tip what could help? Thanks a lot!

Share this post


Link to post
Share on other sites

Tried using getVariable to get the state of the door that way? That should work out, can't give you any code though since I'm in a bit of a hurry.

Share this post


Link to post
Share on other sites

Hi tryteyker,

no I didn't try it - no idea how to get the variable... :o Can you help me?

Share this post


Link to post
Share on other sites

Hey, Undeceived, have you had any success?

I'm trying something similar, but ran out of ideas as well.

Share this post


Link to post
Share on other sites

Try "'Door_Locked_1_rot'". Just know that this anim fires several times (x3) when you try to open a locked door, so you will have to account for that.

Share this post


Link to post
Share on other sites

Larrow, I tried your suggestion, but no success. I tried it this way:

((house animationPhase 'Door_Locked_1_rot') == 1)

Nothing.

Or did you mean something else?

Share this post


Link to post
Share on other sites

Either

((house animationPhase 'Door_Locked_1_rot') == 1)

works ok

This piece of code is just for testing from the debug console and is not an efficient way of doing this but....

terminate h;
h = [] spawn {

while {true} do {
	while {"Building" in ([configFile >> "CFGVehicles" >> typeof cursorTarget, true] call BIS_fnc_returnParents)} do {

		building = cursorTarget;
		cfg = (configFile >> "CFGVehicles" >> typeof building);
		numDoors = getNumber(cfg >> "numberOfDoors");

		for "_i" from 1 to numDoors do {
			building setVariable [format ["bis_disabled_Door_%1", _i], floor (random 2)];
		};

		while {building == cursorTarget} do {

			for "_i" from 1 to numDoors do {

				if (building animationPhase (format ["Door_Locked_%1_rot", _i]) == 1) then {
					hintSilent format ["Door %1 is LOCKED", _i];
				};

			};		
		};


		for "_i" from 1 to numDoors do {
			building setVariable [format ["bis_disabled_Door_%1", _i], 0, true];
		};

	};
};
};

Place yourself in the editor, preview the mission and run the above code from the debug console. Any building that you approach if it has doors, each door will have a 50% chance its locked. On trying to open the door (if locked) will hint to you that it is.

commented code:

terminate h;
h = [] spawn {
//loop forever
while {true} do {
	//loop while looking at a building
	while {"Building" in ([configFile >> "CFGVehicles" >> typeof cursorTarget, true] call BIS_fnc_returnParents)} do {

		//information about building
		building = cursorTarget;
		cfg = (configFile >> "CFGVehicles" >> typeof building);
		numDoors = getNumber(cfg >> "numberOfDoors");

		//randomly lock each door
		for "_i" from 1 to numDoors do {
			building setVariable [format ["bis_disabled_Door_%1", _i], floor (random 2)];
		};

		//loop while we continue to look at the same building
		while {building == cursorTarget} do {

			for "_i" from 1 to numDoors do {

				//Check each door to see if its playing the locked animation
				if (building animationPhase (format ["Door_Locked_%1_rot", _i]) == 1) then {
					hintSilent format ["Door %1 is LOCKED", _i];
				};

			};		
		};

		//unlock all the doors when we are no longer looking at the building
		for "_i" from 1 to numDoors do {
			building setVariable [format ["bis_disabled_Door_%1", _i], 0, true];
		};

	};
};
};

  • Like 1

Share this post


Link to post
Share on other sites

Larrow, you're a treasure for mankind (no kidding)! :notworthy: Thanks a lot, I really couldn't find a solution for this for months!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×