Jump to content
Sign in to follow this  
RecondoLRRP

unlock door/computer

Recommended Posts

I would like to know if it is possible for the mission to require someone to face an object, such as a door or a laptop for a certain amount of time in order to simulate picking a lock or hacking the computer to get intel. The challenge for the players is that since one person has to face the door in order to unlock it, someone else has to cover his back.

Share this post


Link to post
Share on other sites

One scenario could be achieved with the following steps:

  1. Add an action to the object you want to interact with (door/pc or whatever)
  2. When the action is picked, the associated script is run
  3. Now start a timer in the script - you should do this using a spawn so the timer will decrease independently
  4. Start a while-loop in which you check the cursorTarget and compare it to the object the player is looking
    • If the cursorTarget is not for example the door, stop the timer and display an appropriate message and re-add the action to the object
    • When the timer is expired and the player looked at the object the whole time, stop the while-loop and do whatever you want to do at this point

The only problem using cursorTarget is: it can be a bitch sometimes :D

Looking at small objects like a laptop will be slightly okay if your character doesn't move and looks straight to the object, but looking at objects which are stacked together with just a small gap between them will cause the cursorTarget-command to return another object even if you just as move your character for an inch.

Another way to do this would be using "eyePos" and add a tolerance area but yeah, this is overkill imho.

// edit: here's an example script, didn't test it so could be buggy.

create a script named "hacking.sqf" and paste this code in there:

_refObj = _this select 0;
_player = _this select 1;
_actID 	= _this select 2;

// Remove the action so you can't hack twice!
_refObj removeAction _actID;

playerIsHacking = true;
hackTime		= 10;	// in seconds
maxBars			= 20;
char			= "#";

_timer = {
_bars = "";
_quotient = 0;
for "_time" from hackTime to 1 step -1 do
{
	_quotient = ceil((_time/hackTime) * maxBars);

	_bars = "";
	for "_i" from 1 to _quotient do {
		_bars = _bars + char;
	};
	for "_i" from _quotient+1 to maxBars do
	{
		_bars = _bars + " ";
	};

	hintsilent format["Hacking in progress:\n[%1]", _bars];
	sleep 1;
};
playerIsHacking = false;
};

_timerHandle = [] spawn _timer;
waitUntil {!playerIsHacking || cursorTarget != _refObj};
hintsilent "";

// So why did we get here?
if (playerIsHacking) then 
{
// The player did look away! You're a bad, bad boy!
terminate _timerHandle;
hint "Hacking aborted!";

// Re-Enable action (optional);
_refObj addAction ["Hack Laptop", "hacking.sqf", nil, 6, false, true, "", "_target distance _this < 2"];
}
else
{
// WE DID IIIIIT!
hint "Hacking successful - hacked into FBI database";

// Now do what you want here, preferably execVM another script.

};
playerIsHacking = false;

Place an object in the editor (I took a laptop) and put this into the init-field:

this addAction ["Hack Laptop", "hacking.sqf", nil, 6, false, true, "", "_target distance _this < 2"];

Edited by XxAnimusxX
the "removeAction" was bein used the wrong way, corrected.

Share this post


Link to post
Share on other sites

You can check if player is facing object with direction player command and some geometry calculations. There are also built in BIS functions you can use for that but in my experience you are better off writing your own.

Share this post


Link to post
Share on other sites

OK let's see this scenario. In order to hack the laptop, you will also need a special key (you'd probably find it on one of the dead guards). How would you check to see if the player has the key in his gear and then run the script?

Share this post


Link to post
Share on other sites

Put all your guard's references into an array and randomly pick out one of them to hold the key.

myGuards = [myGuard1, myGuard2, myGuard3  // ....];

// ...
_guardHoldingKey = myGuards select ( floor( random(count myGuards) ) );
_guardHoldingKey setVariable ["holdingKey", true];

Now add actions to the guards (for example when they're dead) like "Search for key" and when the action is picked, look if the above variable is set.

// In the SQF-file which is called upon picking the action attached to the guards
_target = _this select 0;
_caller = _this select 1;

_target removeAction (_this select 2);
_keyFound = _target getVariable ["holdingKey", false];

_target setVariable ["holdingKey", nil];

player setVariable ["keyFound", _keyFound];

if (_keyFound) then
{
    hint "Got the key!";
}
else
{
   hint "He didn't have the key";
};

Now you'd need to slightly alter the addAction in the laptop's init-field:

this addAction ["Hack Laptop", "hacking.sqf", nil, 6, false, true, "", "(_target distance _this < 2) && (_this getVariable ['keyFound', false])"];  

Here's a list with script examples which should contain one or more script fitting your scenario.

If you want to have an object act as a key (or a real key, I think there was one as an evidence type of object) you'd put it into the gear of the guard which is randomly picked and check for it in the condition-area of the addAction.

The commands you'd use for that are:

addMagazine, magazines

Edited by XxAnimusxX

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  

×