Jump to content
socs

Lock/Unlock Vehicles

Recommended Posts

Hey guys, back yet again with another question lol... This time I'm just looking for a simple way to lock a helicopter and be able to unlock it once a player has found the "keys" so to speak... Any way to do this? All help is much appreciated...

Share this post


Link to post
Share on other sites

Something like:

_vehicle lock 2;
player setVariable ["hasKeys", false, true];
_object addAction ["Pickup Keys",
{
	player setVariable ["hasKeys", true, true];
	player removeAction (_this select 2);
}, [], 0, false, false, "", ""];

_lockStatus = if (locked _vehicle > 1) then {"Unlock"} else {"Locked"};

_vehicle addAction [format ["%1 %2", _lockStatus, getText (configFile >> "CfgVehicles" >> typeOf cursorObject >> "displayName")],
{
	if (locked _vehicle > 1) then
	{
		_vehicle lock 0;
	} else
	{
		_vehicle lock 2;
	};
}, [], 0, false, false, "", "_this getVariable ""hasKeys"""];

None of this is tested but should give you an idea / good start. _object and _vehicle will need to be changed accordingly.

  • Like 2

Share this post


Link to post
Share on other sites
_vehicle addAction [ format [ "%1 %2", [ "Lock", "Unlock" ] select ( locked _vehicle > 1 ), getText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "displayName") ], {
	params [ "_target", "_caller", "_id", "_args" ];
	
	_vehicleName = getText (configFile >> "CfgVehicles" >> typeOf _target >> "displayName");
	
	if ( locked _target > 1 ) then {
		_target lock 0;
		_target setUserActionText [ _id, format[ "Lock %1", _vehicleName ] ];
	}else{
		_target lock 2;
		_target setUserActionText [ _id, format[ "Unlock %1", _vehicleName ] ];
	};
}, [], 0, false, false, "", "_this getVariable [ 'hasKeys', false ]"];
Spoiler

this addAction [ format [ "%1 %2", [ "Lock", "Unlock" ] select ( locked this > 1 ), getText (configFile >> "CfgVehicles" >> typeOf this >> "displayName") ], {
	params [ "_target", "_caller", "_id", "_args" ];
	
	_target lock ( [ 2, 0 ] select ( locked _target > 1 ) );
	_target setUserActionText [ _id, format[ "%1 %2", [ "Lock", "Unlock" ] select ( locked _target > 1 ), getText (configFile >> "CfgVehicles" >> typeOf _target >> "displayName") ] ];
	
}, [], 0, false, false, "", "_this getVariable [ 'hasKeys', false ]"];

Not so easy to read, so I'll hide it here :D

 

  • Like 2
  • Thanks 2

Share this post


Link to post
Share on other sites

Even better, @Larrow! Nice select in the format. Didn't think of that.

Share this post


Link to post
Share on other sites

Fun! We could even think about specific keys for each vehicles (as in real life):

 

addAction condition becomes:

"_this getVariable ['vehicleKey','none'] isEqualTo _target getVariable ['vehicleKey','keyPass'] ]"

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

×