Jump to content
zonekiller

Adding Scripted Weapons With Attached Items To AmmoBox

Recommended Posts

 

Is there a command or function that will let you add Scripted Weapons With Attached Items To AmmoBox or Vehicle.

 

There is this command for retrieving the weapon and attachment from a ammobox      _array =  (weaponsItemsCargo _weaponholder);   

 

That gives you something like this

_array = [["arifle_MXM_khk_F","muzzle_snds_H","acc_pointer_IR","optic_DMS",["30Rnd_65x39_caseless_mag",30],"bipod_01_F_blk"],
["hgun_Pistol_heavy_02_F","","","",["6Rnd_45ACP_Cylinder",6],""],
["hgun_Pistol_heavy_02_F","","","",["6Rnd_45ACP_Cylinder",6],""]];

 

This is great for backing up to the InIDBi2 database

 

The Issue is how to but it back into a vehicle or ammobox from the database as there is no addweaponsItemsCargo command

 

Anyone got any ideas ??

 

Share this post


Link to post
Share on other sites

there is nothing on the wiki as far as I can see.

i guess you can only add the parts of the weapon and the weapon itself to the container, but you probably cant throw them in there combined.

Share this post


Link to post
Share on other sites

Tricky way: create dummy unit (invisible / no simulation) -> add weapon with attachments -> put weapon to the box -> delete unit

Share this post


Link to post
Share on other sites

 

 

3 hours ago, serena said:

Tricky way: create dummy unit (invisible / no simulation) -> add weapon with attachments -> put weapon to the box -> delete unit

 

@serena,   Top marks that is how I have done it. except (no simulation) the unit needs to complete the animation to add the items

 

I was hoping there was a simpler way.

 

 

Here's the code if anyone's interested

 

_myloadout = 
{
params ["_myunit","_WEAPONS"];

_x = _WEAPONS;

_armed = 0;
_gun = _x select 0;
_item_1 = _x select 1;
_item_2 = _x select 2; 
_item_3 = _x select 3;  
_item_4 = "";
_item_5 = "";
_item_6 = "";

if (count _x > 4) then 
{
if (typename (_x select 4) == "ARRAY") then [{if !(_myunit canAdd (_x select 4)) then {_armed = 4}else{_myunit addMagazine (_x select 4)}},{_item_4 = (_x select 4)}];
};

if (count _x > 5) then 
{
if (typename (_x select 5) == "ARRAY") then [{if !(_myunit canAdd (_x select 5)) then {_armed = 5}else{_myunit addMagazine (_x select 5)}},{_item_5 = (_x select 5)}];
};

if (count _x > 6) then 
{
if (typename (_x select 6) == "ARRAY") then [{if !(_myunit canAdd (_x select 6)) then {_armed = 6}else{_myunit addMagazine (_x select 6)}},{_item_6 = (_x select 6)}];
};

if (_armed > 0) then {if (backpack _myunit == "") then {_myunit addBackpack "B_AssaultPack_blk";_myunit spawn {sleep 2;removeBackpack _this}};_myunit addMagazine (_x select _armed);_armed = 0};

_type = "";

if (_gun != "") then {
_myunit addWeaponGlobal _gun;
_namesound = gettext(configfile >> "CfgWeapons" >> _gun >> "nameSound");

if ((_namesound == "rifle") or (_namesound == "mgun")) then {_type = "r"};
if ((_namesound == "aalauncher") or (_namesound == "atlauncher")) then {_type = "s"};
if (_namesound == "Pistol") then {_type = "h"};
};

_items = [_item_1,_item_2,_item_3,_item_4,_item_5,_item_6];

for "_i" from 0 to 5 do
{
_myitem = _items select _i;
if ((_myitem != "") && (_type == "r")) then {_myunit addPrimaryWeaponItem _myitem};
if ((_myitem != "") && (_type == "s")) then {_myunit addSecondaryWeaponItem _myitem};
if ((_myitem != "") && (_type == "h")) then {_myunit addHandgunItem _myitem};
};

};

//-------------------------------------------------------------------------------------------------------------

[_Module,_items,_myloadout] spawn 
{
params ["_VEH","_items","_myloadout"];
_centre = createCenter East;
_grp = createGroup east;
_dude = objnull;
_pos = [0,0,0];
_dude = _grp createUnit ["O_Soldier_unarmed_F", _pos, [], 0, ""];
_dude allowdamage false;
removeheadgear _dude; 
removeAllAssignedItems _dude; 
removeBackpackGlobal _dude; 
_dude unassignItem "NVGoggles";
_dude removeItems "NVGoggles";
removeAllItems _dude;
{_man removeMagazine _x} forEach magazines _dude;
removeAllWeapons _dude;
_dude disableAI "MOVE";
_dude disableAI "FSM";
_dude disableAI "AUTOTARGET";
_dude addBackpack "B_AssaultPack_blk";
_dude setVariable ["READY", false, false];
_dude addEventHandler ["AnimDone", {(_this select 0) setVariable ["READY", true, false];}];


		{if (count _x > 2) then
			{
			[_dude,_x] call _myloadout;
			sleep 1;
			_dude action ["DropWeapon", _VEH, (_x select 0)];
			sleep 1;
			waituntil {_dude getVariable "READY"};
			_dude setVariable ["READY", false, false];
			sleep 1;
			}else{
			_VEH addItemCargoGlobal _x;
			}} foreach _items;

sleep 5;
deletevehicle _dude;
};

 

 

Share this post


Link to post
Share on other sites
//_namesound = gettext(configfile >> "CfgWeapons" >> _gun >> "nameSound");
//if ((_namesound == "rifle") or (_namesound == "mgun")) then {_type = "r"};
//if ((_namesound == "aalauncher") or (_namesound == "atlauncher")) then {_type = "s"};
//if (_namesound == "Pistol") then {_type = "h"};

GetWeaponType = { //-1 - unknown, 0 - primary, 1 - handgun, 2 - secondary, 3 - binocular
	[1, 2, 4, 4096] find getNumber (configFile >> "CfgWeapons" >> _this >> "Type")
};

// Usage:
private _weaponType = "MySuperHeavyMachineGun" call GetWeaponType;

 

//if ((_myitem != "") && (_type == "r")) then {_myunit addPrimaryWeaponItem _myitem};
//if ((_myitem != "") && (_type == "s")) then {_myunit addSecondaryWeaponItem _myitem};
//if ((_myitem != "") && (_type == "h")) then {_myunit addHandgunItem _myitem};

unit addWeaponItem [weaponName, itemName]
unit addWeaponItem [weaponName, [itemName, ammoCount, muzzleName]]

 

Share this post


Link to post
Share on other sites
unit addWeaponItem [weaponName, [itemName, ammoCount, muzzleName]]
I will test this but not sure it will do tripod and flashlight  -- hmmmm

 

_type  = getNumber (configFile >> "CfgWeapons" >> _gun >> "Type");

switch (_type) do

 

is a good idea :)  thankls 

Share this post


Link to post
Share on other sites

This simple function equip unit with custom fitted weapon, loaded with specified magazines with default or custom ammo count:

EquipUnitWithCustomWeapon = {
	params ["_unit", "_weapon", "_parts"];
	_unit addWeaponGlobal _weapon;
	{	_unit addWeaponItem [_weapon, _x]
	} forEach _parts;
};


// Usage:
[player, "arifle_MX_GL_F", ["muzzle_snds_H","acc_pointer_IR","optic_Arco",["30Rnd_65x39_caseless_mag",30],["1Rnd_HE_Grenade_shell",1]]]
	call EquipUnitWithCustomWeapon;

* count of ammo in magazine - optional

Share this post


Link to post
Share on other sites
4 hours ago, serena said:

This simple function equip unit with custom fitted weapon, loaded with specified magazines with default or custom ammo count:

 

_array =  (weaponsItemsCargo _weaponholder);

_dude = player;

 

{

            _gun = _x select 0;
            _wep_items = _x - [_gun];
            _dude addWeaponGlobal _gun;
            {_dude addWeaponItem [_gun, _x]} forEach _wep_items;

 

} foreach _array;

 

 

works like a charm - Thanks

Share this post


Link to post
Share on other sites

Two array allocations, array comparsion and copy operations in one line: _wep_items = _x - [_gun]

 

Share this post


Link to post
Share on other sites
EquipUnitWithCustomWeapons = {
	params ["_unit", "_weapons"];
	{	private _weapon = nil;
		{
			if (_forEachIndex > 0)
				then {_unit addWeaponItem [_weapon, _x]}
				else {_weapon = _x; _unit addWeaponGlobal _weapon}
		} forEach _x
	} forEach _weapons
};


// Add custom pistol and rifle
[player, [
	["arifle_MX_GL_F", "muzzle_snds_H","acc_pointer_IR","optic_Arco",["30Rnd_65x39_caseless_mag"],["1Rnd_HE_Grenade_shell"]],
	["hgun_Pistol_heavy_01_F","muzzle_snds_acp","optic_MRD",["11Rnd_45ACP_Mag",11]]]] call EquipUnitWithCustomWeapons;	

 

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

×