Jump to content
Sign in to follow this  
Boerstil

Get/Set Vehicle inventorys.

Recommended Posts

Someone was requesting this function in dev-branch forum. So I'll share my script for it.

It basically does what it sounds like.

Use function where unit is local.

 

loadout = [unit] call bor_fnc_getVehicleLoadout;

 

[unit ,loadout] call bor_fnc_setVehicleLoadout;

 

Parameters: 

unit: Object
loadout: Array from getVehicleLoadout

 

 

bor_fnc_getVehicleLoadout =
{

if (!local (_this select 0)) exitWith {};

params ["_veh"];
 
private _magArray = [];
	private _wepArray = []; 
		private _itemArray = []; 
			private _bpArray = [];

{
	private ["_mag"];                   
	
	_mag = 
		[
			(((getMagazineCargo _veh) select 0) select _forEachIndex)
		,
			(((getMagazineCargo _veh) select 1) select _forEachIndex)
		];
	_magArray pushBack _mag;
	
} forEach ((getMagazineCargo _veh) select 0);

	{
		private ["_mag"];                   
	
		_wep = 
			[
				(((getWeaponCargo _veh) select 0) select _forEachIndex)
			,
				(((getWeaponCargo _veh) select 1) select _forEachIndex)
			];
		_wepArray pushBack _wep;
		
	} forEach ((getWeaponCargo _veh) select 0);
	
		{
			private ["_item"];                   
	
			_item = 
				[
					(((getItemCargo _veh) select 0) select _forEachIndex)
				,
					(((getItemCargo _veh) select 1) select _forEachIndex)
				];
			_itemArray pushBack _item;
			
		} forEach ((getItemCargo _veh) select 0);

			{
				private ["_bp"];                   
	
				_bp = 
					[
						(((getBackpackCargo _veh) select 0) select _forEachIndex)
					,
						(((getBackpackCargo _veh) select 1) select _forEachIndex)
					];
				_bpArray pushBack _bp;
			
			} forEach ((getBackpackCargo _veh) select 0);


_loadout = 	[
			_magArray,
			_wepArray,
			_itemArray,
			_bpArray
			];

_loadout

};





bor_fnc_setVehicleLoadout =
{
if (!local (_this select 0)) exitWith {};

params ["_veh","_loadout"];
 
private _magArray = (_loadout select 0);
	private _wepArray = (_loadout select 1);
		private _itemArray = (_loadout select 2);
			private _bpArray = (_loadout select 3);

			
clearWeaponCargoGlobal _veh;
	clearMagazineCargoGlobal _veh;
		clearItemCargoGlobal _veh;
			clearBackpackCargoGlobal _veh;			
			
						
{                
	
	_veh addMagazineCargoGlobal _x;
	
} forEach _magArray;

	{                 
	
		_veh addWeaponCargoGlobal _x;
		
	} forEach _wepArray;
	
		{               
	
			_veh addItemCargoGlobal _x;
			
		} forEach _itemArray;

			{                
	
				_veh addBackpackCargoGlobal _x;
			
			} forEach _bpArray;

};

 

Share this post


Link to post
Share on other sites

I think I'll join the party ;)

 

fnc_getVehicleLoadout = 
{
	params ["_veh"];
	private _loadout = [];
	
	{
		_x params ["_items", "_qtys"];
		_loadout set [_forEachIndex, _items apply {[_x, _qtys deleteAt 0]}];
	}
	forEach [getMagazineCargo _veh, getWeaponCargo _veh, getItemCargo _veh, getBackpackCargo _veh];
	
	_loadout
};
hint str (car call fnc_getVehicleLoadout);

 

Share this post


Link to post
Share on other sites
3 hours ago, killzone_kid said:

I think I'll join the party ;)

 


fnc_getVehicleLoadout = 
{
	params ["_veh"];
	private _loadout = [];
	
	{
		_x params ["_items", "_qtys"];
		_loadout set [_forEachIndex, _items apply {[_x, _qtys deleteAt 0]}];
	}
	forEach [getMagazineCargo _veh, getWeaponCargo _veh, getItemCargo _veh, getBackpackCargo _veh];
	
	_loadout
};

hint str (car call fnc_getVehicleLoadout);

 

 

Impressive KK.

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  

×