Jump to content
SGT Major Ray Jefferson

Command/ Script for ACE3 Key Car in inventory furniture ?

Recommended Posts

Hello, I would like a piece of furniture to contain an ACE 3 key for unlocking a car, or that this is on the piece of furniture.

the class name of the object is ACE_key_civ.

these commands do not work: c1 AddItem "ACE_key_civ"; c1 AddItem "ACE_Kestrel4500"; c1 addItem "optic_aco";

Thank you for your help.

Share this post


Link to post
Share on other sites

ACE_key_civ is not a "world" object by default, meaning you can't place one in the world in the editor or through a simple command like addItem. You can place them in an object's inventory in the editor, or you can use the provided framework to script them into existence:
https://ace3mod.com/wiki/framework/vehiclelock-framework.html

 

You could also do something like place Land_Key_01_F somewhere and initiate the above framework through an addAction/holdAction, deleting the static key object when you "pick up" the vehicle keys.

  • Like 1

Share this post


Link to post
Share on other sites

The framework does not work with the crate or the furniture.

[m1, v1, true] call ace_vehiclelock_fnc_addKeyForVehicle; or [c1, v1, true] call ace_vehiclelock_fnc_addKeyForVehicle;

Share this post


Link to post
Share on other sites
25 minutes ago, SGT Major Ray Jefferson said:

The framework does not work with the crate or the furniture.


Of course not, it assigns a vehicle's key to the player.

It doesn't do what you want it to, but my suggested workaround will sort of.
 

Share this post


Link to post
Share on other sites

@SGT Major Ray Jefferson

You might be looking for different command. This might do what you're trying to achieve if it's ok that it's just an inventory item and it's not visible ON the furniture.

c1 addItemCargo ["ACE_key_civ", 1];

 

  • Like 2

Share this post


Link to post
Share on other sites
43 minutes ago, soldierXXXX said:

addItemCargo


Ahh, ya know, that works just fine. I was ASS-uming things about the nature of the ACE vehicle key.

Depending on use case, you might consider the global variant addItemCargoGlobal.

  • Like 2

Share this post


Link to post
Share on other sites

No that´s not possible. That´s because when using  ace_vehiclelock_fnc_addKeyForVehicle with customKey parameter set to TRUE, the script behaves differently (and works only in MP environment). The script works with command magazinesDetail which returns vehicle/unit magazines with their specific ID, but it can´t return magazines from object that can´t shoot (will return [] for objects like civil cars, boxes etc...). Your best bet for making custom key for the car is to add the key directly to player with 

[player, car1, true] call ACE_VehicleLock_fnc_addKeyForVehicle;

 and not into furniture.

  • Like 2

Share this post


Link to post
Share on other sites

As in my first post, you could place a "dummy" key with an addAction/holdAction (or since this is an ACE function, an ACE interaction!) on the table that initiates the ACE function (and deletes the dummy key).

//place in init of key object (e.g. "Land_Key_01_F") named "key1"
//name your car "car1"
//change these variable names as desired

_keyAction = [
"keys_01", 
"Take Keys", 
"", 
{   
	params ["_target", "_player", ""];
    [_player, car1, true] call ace_vehiclelock_fnc_addKeyForVehicle;
    deleteVehicle _target;
}, 
{true}
] call ace_interact_menu_fnc_createAction;
 
[key1, 0, ["ACE_MainActions"], _keyAction] call ace_interact_menu_fnc_addActionToObject; 

If the key is inside a desk, you could use a Take EventHandler that initiates the function and deletes the original key (which is a skeleton key for all cars of its side, which you don't want).

//place in player init

this addEventHandler ["Take", {
	params ["_unit", "_container", "_item"];
	if (_item == "ACE_key_civ") then 
	{
	    _unit removeItem _item;
        [_unit, car1, true] call ace_vehiclelock_fnc_addKeyForVehicle;
	}	
}];

The former event handler could also be added/removed dynamically, maybe on condition of distance from the container.

 

Here's a basic example mission. There is a set of keys on the table in front of the player that will unlock the car on the left. Inside the desk to the right is a set of keys that will unlock the car on the right.

https://www.dropbox.com/sh/0xtj8fi5bfcz59w/AADmcBjkwyWuTH_LloYbsk7Fa?dl=0

  • Like 2

Share this post


Link to post
Share on other sites

Hi again. The code that wrote @Harzach is great 🙂. I like specialy the function that adds interaction to the key 😄 so cool. And i have to correct myself for i thought the function is only available for multiplayer-that is not true it works perfectly fine in SP. IDK why it didn´t work yesterday when i tried it 😄. However one thought got on my mind and that was what if you wanted to create like keybox ? Where you want to have keys for more than one vehicle (assigned keys) and you don´t wish to use civil key as dummy key (to not look so obvious)? Well when i dig deeper into ace code and i figured out if you want to have key registered you only have to register it to object variable ""ace_vehiclelock_customkeys"" and the vehicle lock system takes care of the rest. So i had an idea for such script. It´s also created with Take eventhandler but it could be adjusted for more cars. If you´re interested take a look 🙂. I put this into init.sqf and as i tested it, it should work-keys stays assigned as they were. You can place them on ground, back into furniture or inside cars (sometimes it´s a bit hard to detect which key you actually have). Well you can ignore this post if you want 😄 i just wanted to post it for anyone that might be interested in same thing 🙂. only thing you have to adjust is:

c1 addMagazineCargoGlobal ["ACE_key_customKeyMagazine", 3];
c1 setVariable ["availableKeysCars",[car1,car1_1,car1_2]];

where c1 is the furniture, 3 is number of keys to be added and  [car1,car1_1,car1_2] is the array for vehicles in order that will get their key registered when you take the keys from furniture. And if you want more units to be able to register the keys, they need to have the same eventhandler and it will work (tested with another playable unit).
At the start player has two already registered keys for car1 in his inventory (i wanted to test it if it´s possible to register keys without using ace action and kept it there).
 

//=========================================================================================================================================================================================================
//with this you can automaticly assign more than one key that you already have in inventory to unlock car1-great at mission start-usefull when you want to give access to car1 to someone else but you want another key to be able to un/lock it
player addMagazine "ACE_key_customKeyMagazine";
player addMagazine "ACE_key_customKeyMagazine";
arrayActiveKeys = [];//this array is most important-needs to be available for both functions-checks all active keys
{if (((toLowerANSI _x) find "ace vehicle key") != -1) then {arrayActiveKeys pushBack _x};} forEach (magazinesDetail player);//this registers keys from players inventory
//hint str arrayActiveKeys;
private _copyArrayActiveKeys = +arrayActiveKeys;
car1 setVariable ["ace_vehiclelock_customkeys",_copyArrayActiveKeys];//this syntax setups the keys that player has in inventory for car1
//=========================================================================================================================================================================================================
//this is a function to simulate more than one key in furniture-needs to be assigned by Take eventhandler
//Be aware that for Multiplayer usage the code would probably need some tweaks (like publicVariable arrayActiveKeys and so on)
c1 addMagazineCargoGlobal ["ACE_key_customKeyMagazine", 3];//number of  keys should match  with availableKeysCars array
c1 setVariable ["availableKeysCars",[car1,car1_1,car1_2]];//you can copy this and assign different vehicles for different furnitures 
f1 addMagazineCargoGlobal ["ACE_key_customKeyMagazine", 2];
f1 setVariable ["availableKeysCars",[b1,b2]];

soldierXXXX_fnc_Get_AddedKey = {
		                private _foundKeys = [];
		                {if (((toLowerANSI _x) find "ace vehicle key") != -1) then {_foundKeys pushBack _x};} forEach (magazinesDetail _this);
		                private _foundNewKeys = [];
		                {if (!(_x in arrayActiveKeys)) then {_foundNewKeys pushBack _x};} forEach _foundKeys;
		                if (_foundNewKeys isNotEqualTo []) exitWith {_foundNewKeys select 0};
		                ""//returns "" if the key is registered
                               };
soldierXXXX_fnc_ACE_VehLock_TakeEH = {
                                      params ["_unit", "_container", "_item"];
				      private _AddedKey =_unit call soldierXXXX_fnc_Get_AddedKey;
				      if (_AddedKey == "") exitWith {hint "This key is already registered"};
				      if (_container getVariable ["availableKeysCars",[]] isNotEqualTo []) then {//if the container has unregistered keys available
												                  private _currentCarAvailable = _container getVariable "availableKeysCars";
												                  private _currentCar = (_currentCarAvailable select 0);
									                                          private _currentACEVEHvar = (_currentCar getVariable ["ace_vehiclelock_customkeys",[]]);
									                                          _currentACEVEHvar pushBack _AddedKey;
													          arrayActiveKeys pushBack _AddedKey;
									                                          _currentCar setVariable ["ace_vehiclelock_customkeys",_currentACEVEHvar];
												                  _currentCarAvailable deleteAt 0;
										                                  _container setVariable ["availableKeysCars",_currentCarAvailable];
											                          hint format ["Key taken for:%1\nUnreleased keys available for:%2",_currentCar,(_container getVariable "availableKeysCars")];
									                                      };
                                    };

player addEventHandler ["Take", {
	                          params ["_unit", "_container", "_item"];
			          if ((_item isEqualTo "ACE_key_customKeyMagazine")) exitWith {
								                               _this spawn soldierXXXX_fnc_ACE_VehLock_TakeEH;
								                              };
                                }];
//============================================================================================================================================================================================================

I´m attaching Uploaded mission (stored for 30 days) . If you interested you can try it 🙂

  • Like 2

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

×