Jump to content
Sign in to follow this  
_qor

Swap weapons from vehicleCargo

Recommended Posts

Hey,

 

I added some weapons and magazines to a vehicle's cargo. Is there a way to swap this weapon-setup, which may have changed, to an ammobox?

 

Cant find a way to do this by getWeaponCargo and weapons only returns "TruckHorn".

I think there is a way to do this with getWeaponCargo, otherwise this code would have been introduced only to make the cargo visible.

 

Unfortunately pickWeaponPool and putWeaponPool doesnt work. I read some posts mentioning that those codes do work.

Share this post


Link to post
Share on other sites


_weaponsCargo = getWeaponCargo _vehicle; // [[<type1>, ...], [<quantity1>, ...]]

clearWeaponCargoGlobal _vehicle;

_types = _weaponsCargo select 0;

_quantities = _weaponsCargo select 1;

_weaponsCargo = [];

{

_weaponsCargo set [

count _weaponsCargo,

[_x, _quantities select _forEachIndex]

];

}

forEach _types;

// Now _weaponsCargo looks like [[<type1>, <quantity1>], ...]

{if ((_x select 0) == "SCAR_L_STD_HOLO") exitWith {_weaponsCargo = [_weaponsCargo, _forEachIndex] call BIS_fnc_removeIndex}} forEach _weaponsCargo; // Deletes SCAR_L_STD_HOLO rifles

{_vehicle addWeaponCargoGlobal _x} forEach _weaponsCargo;

Share this post


Link to post
Share on other sites

Wow, excellent!!!

Exactly what I was looking for!

 

So you call BIS_fnc_removeIndex to remove the each existing weapon from the vehicle?

Or does this just removes the preexisting weapons in the ammunition MTVRs?

 

Script works great for weapons, but not for magazines.

I dont really know how to adapt the script. 

{_vehicle addMagazineCargoGlobal _x} forEach _weaponsCargo; returns onlythe given  weapons.

Share this post


Link to post
Share on other sites

So you call BIS_fnc_removeIndex to remove the each existing weapon from the vehicle?

I used this function to remove subarray from array, because it's impossible to do it using subtraction.

 

Or does this just removes the preexisting weapons in the ammunition MTVRs?

My code deletes SCAR_L_STD_HOLO if it is in cargo, otherwise nothing happens.

 

Script works great for weapons, but not for magazines.

I dont really know how to adapt the script.

{_vehicle addMagazineCargoGlobal _x} forEach _weaponsCargo; returns onlythe given  weapons.

_magazinesCargo = getMagazineCargo _vehicle;
 
clearMagazineCargoGlobal _vehicle;
 
_types = _magazinesCargo select 0;
_quantities = _magazinesCargo select 1;
 
_magazinesCargo = [];
 
{
	_magazinesCargo set [
		count _magazinesCargo,
		[_x, _quantities select _forEachIndex]
	];
}
forEach _types;
 
{if ((_x select 0) == "30Rnd_556x45_Stanag") exitWith {_magazinesCargo = [_magazinesCargo, _forEachIndex] call BIS_fnc_removeIndex}} forEach _magazinesCargo;
 
{_vehicle addMagazineCargoGlobal _x} forEach _magazinesCargo;

Share this post


Link to post
Share on other sites

Ah, thought _weaponsCargo would also contain information about magazines.

 

Works great, thanks a lot for those scripts! 

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  

×