Jump to content
fn_Quiksilver

[Code Snippet] Transfer loadouts from VAS to Virtual Arsenal

Recommended Posts

QS_fnc_clientVAS2VA = {
/*
		File: fn_clientVAS2VA.sqf
		Author:

			Quiksilver
			
		Last modified:

			22/12/2015 ArmA 1.54 by Quiksilver
			
		Description:

			Transfer loadouts from Virtual Ammobox System to Virtual Arsenal
________________________________________________________________*/
	if (isDedicated) exitWith {};
	if (!isNil {profileNamespace getVariable 'QS_VAStoArsenal'}) exitWith {};
	profileNamespace setVariable ['QS_VAStoArsenal',TRUE];
	saveProfileNamespace;
	private [
		'_index','_vasLoadout','_vasLoadout_title','_vasLoadout_primary','_vasLoadout_launcher','_vasLoadout_handgun','_vasLoadout_magazines',
		'_vasLoadout_uniform','_vasLoadout_vest','_vasLoadout_backpack','_vasLoadout_items','_vasLoadout_primItems','_vasLoadout_secItems',
		'_vasLoadout_handgunItems','_vasLoadout_uItems','_vasLoadout_vItems','_vasLoadout_bItems','_headgearTypes','_headgear','_gogglesTypes',
		'_binocularTypes','_binocular','_export','_data','_newName','_namespace'
	];
	_index = 0;
	_headgear = '';
	_goggles = '';
	_binocularTypes = ['Rangefinder','Binocular','Laserdesignator','Laserdesignator_02','Laserdesignator_03'];
	_binocular = '';
	_namespace = profileNamespace;
	for '_x' from 0 to 24 step 1 do {
		_vasLoadout = profileNamespace getVariable [format ['vas_gear_new_%1',_index],[]];
		if (!(_vasLoadout isEqualTo [])) then {
			_vasLoadout params [
				'_vasLoadout_title',
				'_vasLoadout_primary',
				'_vasLoadout_launcher',
				'_vasLoadout_handgun',
				'_vasLoadout_magazines',
				'_vasLoadout_uniform',
				'_vasLoadout_vest',
				'_vasLoadout_backpack',
				'_vasLoadout_items',
				'_vasLoadout_primItems',
				'_vasLoadout_secItems',
				'_vasLoadout_handgunItems',
				'_vasLoadout_uItems',
				'_vasLoadout_vItems',
				'_vasLoadout_bItems'
			];
			{
				if (['H_',_x,FALSE] call (missionNamespace getVariable 'BIS_fnc_inString')) then {
					_headgear = _x;
				};
				if (_x in _binocularTypes) then {
					_binocular = _x;
				};
			} forEach _vasLoadout_items;
			_export = [];
			_export = [
				[_vasLoadout_uniform,_vasLoadout_uItems],
				[_vasLoadout_vest,_vasLoadout_vItems],
				[_vasLoadout_backpack,_vasLoadout_bItems],
				_headgear,
				_goggles,
				_binocular,
				[_vasLoadout_primary,_vasLoadout_primItems,((getArray (configFile >> 'CfgWeapons' >> _vasLoadout_primary >> 'magazines')) select 0)],
				[_vasLoadout_launcher,_vasLoadout_secItems,((getArray (configFile >> 'CfgWeapons' >> _vasLoadout_launcher >> 'magazines')) select 0)],
				[_vasLoadout_handgun,_vasLoadout_handgunItems,((getArray (configFile >> 'CfgWeapons' >> _vasLoadout_handgun >> 'magazines')) select 0)],
				['ItemMap','ItemCompass','ItemWatch','ItemRadio','ItemGPS'],
				[(face player),'','']
			];
			_newName = format ['%1 (Imported %2)',_vasLoadout_title,_index];
			_data = _namespace getVariable ['bis_fnc_saveInventory_data',[]];
			_nameID = _data find _newName;
			if (_nameID < 0) then {
				_nameID = count _data;
				_data set [_nameID,_newName];
			};
			_data set [_nameID + 1,_export];
			_namespace setVariable ['bis_fnc_saveInventory_data',_data];
			saveProfileNamespace;
		};
		_index = _index + 1;
		uiSleep 0.1;
	};
};

Compile(final) that function with the CfgFunctions library (or whatever compiler you use) and call it in player init (such as initPlayerLocal.sqf or init.sqf).

 

Will run only once per profile.

 

I'm not sure if BI changed the ordering of their Virtual Arsenal inventory loadouts regarding magazines, that could be an issue, someone would have to doublecheck how Arsenal saves/loads inventory, as this function may predate those changes. There also may be a new Laser Designator or Rangefinder class with Apex, if anyone knows the new ones, I'll update the post with it.

 

Use like this:

 

comment "Insert the below line into initPlayerLocal.sqf or init.sqf or wherever your client files initialize from";
call QS_fnc_clientVAS2VA;

 

  • Like 1

Share this post


Link to post
Share on other sites

Couple of notes..

  • You do not supply your QS_fnc_inString
  • You are getting the primary mag for the handgun
  • BIS_fnc_itemType is an easier way to get the items out of _vasLoadout_items
  • NVGs, facewear and gps/uavTerminal are available from _vasLoadout_items
  • ItemGPS could be a gps or uav terminal
  • no need to save the data each loop, just update it and save once finished

 

 

Spoiler

From the debugConsole in either 3Den or during a mission, or from initPlayerLocal.sqf


_vasLoadout_face = if ( is3DEN && { face player == "" } ) then {
	create3DENEntity ["Object","B_Soldier_F",[0,0,0]];
	_face = face player;
	delete3DENEntities [ player ];
	_face
}else{
	face player;
};
_BIS_data = profileNamespace getVariable ['bis_fnc_saveInventory_data',[]];
{
	_vasLoadout = profileNamespace getVariable [ _x, [] ];

	_vasLoadout params [
		'_vasLoadout_title',
		'_vasLoadout_primary',
		'_vasLoadout_launcher',
		'_vasLoadout_handgun',
		'_vasLoadout_magazines',
		'_vasLoadout_uniform',
		'_vasLoadout_vest',
		'_vasLoadout_backpack',
		'_vasLoadout_items',
		'_vasLoadout_primItems',
		'_vasLoadout_secItems',
		'_vasLoadout_handgunItems',
		'_vasLoadout_uItems',
		'_vasLoadout_vItems',
		'_vasLoadout_bItems'
	];
	[] params[
		[ '_vasLoadout_binocular', "" ],
		[ '_vasLoadout_headgear', "" ],
		[ '_vasLoadout_facewear', "" ],
		[ '_vasLoadout_gps', "" ],
		[ '_vasLoadout_NVGoggles', "" ]
	];
	
	{
		_itemType = _x call BIS_fnc_itemType;
		switch ( toLower( _itemType select 1 ) ) do {
			case "binocular";
			case "laserdesignator" : {
				_vasLoadout_binocular = _x;
			};
			case "headgear" : {
				_vasLoadout_headgear = _x;
			};
			case "glasses" : {
				_vasLoadout_facewear = _x;
			};
			case "uavterminal";
			case "gps" : {
				_vasLoadout_gps = _x;
			};
			case "nvgoggles" : {
				_vasLoadout_NVGoggles = _x;
			};
		};
	} forEach _vasLoadout_items;
	
	_export = [
		[_vasLoadout_uniform,_vasLoadout_uItems],
		[_vasLoadout_vest,_vasLoadout_vItems],
		[_vasLoadout_backpack,_vasLoadout_bItems],
		_vasLoadout_headgear,
		_vasLoadout_facewear,
		_vasLoadout_binocular,
		[_vasLoadout_primary,_vasLoadout_primItems,((getArray (configFile >> 'CfgWeapons' >> _vasLoadout_primary >> 'magazines')) select 0)],
		[_vasLoadout_launcher,_vasLoadout_secItems,((getArray (configFile >> 'CfgWeapons' >> _vasLoadout_launcher >> 'magazines')) select 0)],
		[_vasLoadout_handgun,_vasLoadout_handgunItems,((getArray (configFile >> 'CfgWeapons' >> _vasLoadout_handgun >> 'magazines')) select 0)],
		['ItemMap','ItemCompass','ItemWatch','ItemRadio',_vasLoadout_gps, _vasLoadout_NVGoggles],
		[_vasLoadout_face,'','']
	];
	_newName = format ['%1 (Imported %2)',_vasLoadout_title, _x select [ 13, 2 ]];
	_nameID = _BIS_data find _newName;
	if (_nameID < 0) then {
		_nameID = count _BIS_data;
		_BIS_data set [_nameID,_newName];
	};
	_BIS_data set [_nameID + 1,_export];

}forEach ( allVariables profileNamespace select {_x select [0,12] == "vas_gear_new"} );
	
profileNamespace setVariable ['bis_fnc_saveInventory_data',_BIS_data];
saveProfileNamespace;

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Weird yea I changed QS_fnc_inString to BIS_fnc_inString but it didn't modify the code accordingly. 

 

This has worked fine, helped ease players from the old trusty VAS to the newer VA when it was still fresh. Had riots on servers when loadouts were lost, so this helped the transition.

 

Yours looks a little tighter, I recommend readers to use Larrows version.

 

This was just something from the dusty code vaults that thought some might find handy :)

 

One issue with yours is that it will not work in MP, allVariables cannot access profileNamespace in MP. This is designed for mission makers to insert into their MP mission to seamlessly port loadouts, so MP support necessary. Also IIRC in design there was a reason to save profile each iteration, but don't recall anymore.

 

Also good spot on the handgun mag, never spotted that error, it explains a lot though (empty handguns on imported loadouts)

 

Share this post


Link to post
Share on other sites

One issue with yours is that it will not work in MP

You are correct mine will definitely not work in MP. I didnt realise this is what you were going for, I just thought it was for transferring VAS to VA and initPlayerLocal was just an option so people could just bung the script in said file rather than having to use the debugConsole.

 

Definitely a handy script though.

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

×