sinny 18 Posted April 30, 2016 Hi, I have created my first script where i have listed a bunch of weapons in a variable. I then use the "call BIS_fnc_selectRandom" and then place the content of the variable to "_unit addWeapon" Everything works as i want it, but im having some trouble to add the right kind of magazines to the right kind of weapon. Is there any easy way to match magazines to weapons? So the code looks something like this: And the result is like, the units gets all kinds of magazines... _randomno6=floor random 3; _weapons = ["CUP_arifle_AK107","CUP_arifle_AK47","CUP_arifle_AK74","rhs_weap_ak74m_2mag","rhs_weap_ak74m_2mag_camo","rhs_weap_ak74m_2mag_npz","rhs_weap_ak74m_camo","rhs_weap_ak74m_desert","rhs_weap_ak74m_camo_folded","rhs_weap_ak74m_plummag_folded","rhs_weap_ak74m_desert_folded","rhs_weap_akm","rhs_weap_akms","CUP_arifle_AKS","CUP_arifle_AKS74","CUP_arifle_AKS74U","rhs_weap_asval","CUP_srifle_CZ550","CUP_srifle_CZ550_rail","CUP_srifle_LeeEnfield","CUP_sgun_M1014","CUP_srifle_M14","CUP_srifle_M14_DMR","CUP_srifle_M24_wdl","rhs_weap_M590_8RD","rhs_weap_M590_5RD","CUP_hgun_MicroUzi","CUP_lmg_PKM","rhs_weap_pkm","CUP_lmg_Pecheneg","rhs_weap_pkp","CUP_arifle_RPK74_45","CUP_arifle_RPK74","CUP_arifle_RPK74M","CUP_arifle_Sa58RIS1","CUP_arifle_Sa58RIS1_des","CUP_arifle_Sa58P","CUP_arifle_Sa58P_des","CUP_hgun_SA61","CUP_srifle_SVD","CUP_srifle_SVD_des","rhs_weap_svdp_wd_npz","rhs_weap_svds","CUP_lmg_UK59"] call BIS_fnc_selectRandom; _mags = ["CUP_30Rnd_TE1_Green_Tracer_545x39_AK_M","CUP_30Rnd_762x39_AK47_M","CUP_30Rnd_TE1_Green_Tracer_545x39_AK_M","rhs_30Rnd_545x39_7N10_AK","rhs_30Rnd_545x39_7N22_AK","rhs_30Rnd_545x39_7N10_AK","rhs_45Rnd_545X39_AK_Green","rhs_30Rnd_545x39_AK","rhs_30Rnd_545x39_AK","rhs_30Rnd_545x39_AK_no_tracers","rhs_30Rnd_545x39_7N22_AK","rhs_30Rnd_545x39_AK_no_tracers","rhs_30Rnd_545x39_AK_no_tracers","rhs_30Rnd_762x39mm_tracer","rhs_30Rnd_762x39mm_89","CUP_30Rnd_762x39_AK47_M","CUP_30Rnd_TE1_Green_Tracer_545x39_AK_M","CUP_30Rnd_TE1_White_Tracer_545x39_AK_M","rhs_20rnd_9x39mm_SP6","CUP_5x_22_LR_17_HMR_M","CUP_5x_22_LR_17_HMR_M","CUP_10x_303_M","CUP_8Rnd_B_Beneli_74Slug","CUP_20Rnd_TE1_Yellow_Tracer_762x51_DMR","CUP_20Rnd_TE1_Green_Tracer_762x51_DMR","CUP_5Rnd_762x51_M24","rhsusf_8Rnd_00Buck","rhsusf_5Rnd_00Buck","CUP_30Rnd_9x19_UZI","CUP_100Rnd_TE4_LRT4_762x54_PK_Tracer_Green_M","rhs_100Rnd_762x54mmR_green","CUP_100Rnd_TE4_LRT4_762x54_PK_Tracer_Green_M","rhs_100Rnd_762x54mmR_green","CUP_30Rnd_TE1_Yellow_Tracer_545x39_AK_M","CUP_30Rnd_TE1_Red_Tracer_545x39_AK_M","CUP_30Rnd_TE1_Green_Tracer_545x39_AK_M","CUP_30Rnd_Sa58_M_TracerY","CUP_30Rnd_Sa58_M_TracerY","CUP_30Rnd_Sa58_M_TracerR","CUP_30Rnd_Sa58_M_TracerG","CUP_20Rnd_B_765x17_Ball_M","CUP_10Rnd_762x54_SVD_M","CUP_10Rnd_762x54_SVD_M","rhs_10Rnd_762x54mmR_7N1","rhs_10Rnd_762x54mmR_7N1","CUP_50Rnd_UK59_762x54R_Tracer"] call BIS_fnc_selectRandom; _unit addWeapon _weapons; _unit forceAddUniform _uniform; for "_i" from 1 to _randomno6 do {_unit addItemToUniform _mags;}; Share this post Link to post Share on other sites
soolie 189 Posted April 30, 2016 Hey can't test this right now but should work. I'm guessing that the spot in weapon array matches up with the mag array. _randomno6=floor random 3; // weapon array _weapons = ["CUP_arifle_AK107","CUP_arifle_AK47","CUP_arifle_AK74","rhs_weap_ak74m_2mag","rhs_weap_ak74m_2mag_camo", "rhs_weap_ak74m_2mag_npz","rhs_weap_ak74m_camo","rhs_weap_ak74m_desert","rhs_weap_ak74m_camo_folded", "rhs_weap_ak74m_plummag_folded","rhs_weap_ak74m_desert_folded","rhs_weap_akm","rhs_weap_akms","CUP_arifle_AKS", "CUP_arifle_AKS74","CUP_arifle_AKS74U","rhs_weap_asval","CUP_srifle_CZ550","CUP_srifle_CZ550_rail","CUP_srifle_LeeEnfield", "CUP_sgun_M1014","CUP_srifle_M14","CUP_srifle_M14_DMR","CUP_srifle_M24_wdl","rhs_weap_M590_8RD","rhs_weap_M590_5RD", "CUP_hgun_MicroUzi","CUP_lmg_PKM","rhs_weap_pkm","CUP_lmg_Pecheneg","rhs_weap_pkp","CUP_arifle_RPK74_45","CUP_arifle_RPK74", "CUP_arifle_RPK74M","CUP_arifle_Sa58RIS1","CUP_arifle_Sa58RIS1_des","CUP_arifle_Sa58P","CUP_arifle_Sa58P_des","CUP_hgun_SA61", "CUP_srifle_SVD","CUP_srifle_SVD_des","rhs_weap_svdp_wd_npz","rhs_weap_svds","CUP_lmg_UK59"]; // Gets random weapon _weap = _weapons call BIS_fnc_selectRandom; // Finds index number of weapon in weapons array (_weap = _weapons select x) _arrayNum = _weapons find _weap; //Mags array _mags = ["CUP_30Rnd_TE1_Green_Tracer_545x39_AK_M","CUP_30Rnd_762x39_AK47_M","CUP_30Rnd_TE1_Green_Tracer_545x39_AK_M","rhs_30Rnd_545x39_7N10_AK", "rhs_30Rnd_545x39_7N22_AK","rhs_30Rnd_545x39_7N10_AK","rhs_45Rnd_545X39_AK_Green","rhs_30Rnd_545x39_AK","rhs_30Rnd_545x39_AK", "rhs_30Rnd_545x39_AK_no_tracers","rhs_30Rnd_545x39_7N22_AK","rhs_30Rnd_545x39_AK_no_tracers","rhs_30Rnd_545x39_AK_no_tracers", "rhs_30Rnd_762x39mm_tracer","rhs_30Rnd_762x39mm_89","CUP_30Rnd_762x39_AK47_M","CUP_30Rnd_TE1_Green_Tracer_545x39_AK_M", "CUP_30Rnd_TE1_White_Tracer_545x39_AK_M","rhs_20rnd_9x39mm_SP6","CUP_5x_22_LR_17_HMR_M","CUP_5x_22_LR_17_HMR_M","CUP_10x_303_M", "CUP_8Rnd_B_Beneli_74Slug","CUP_20Rnd_TE1_Yellow_Tracer_762x51_DMR","CUP_20Rnd_TE1_Green_Tracer_762x51_DMR","CUP_5Rnd_762x51_M24", "rhsusf_8Rnd_00Buck","rhsusf_5Rnd_00Buck","CUP_30Rnd_9x19_UZI","CUP_100Rnd_TE4_LRT4_762x54_PK_Tracer_Green_M","rhs_100Rnd_762x54mmR_green", "CUP_100Rnd_TE4_LRT4_762x54_PK_Tracer_Green_M","rhs_100Rnd_762x54mmR_green","CUP_30Rnd_TE1_Yellow_Tracer_545x39_AK_M","CUP_30Rnd_TE1_Red_Tracer_545x39_AK_M", "CUP_30Rnd_TE1_Green_Tracer_545x39_AK_M","CUP_30Rnd_Sa58_M_TracerY","CUP_30Rnd_Sa58_M_TracerY","CUP_30Rnd_Sa58_M_TracerR","CUP_30Rnd_Sa58_M_TracerG", "CUP_20Rnd_B_765x17_Ball_M","CUP_10Rnd_762x54_SVD_M","CUP_10Rnd_762x54_SVD_M","rhs_10Rnd_762x54mmR_7N1","rhs_10Rnd_762x54mmR_7N1","CUP_50Rnd_UK59_762x54R_Tracer"]; // Using weapons array number, finds mag with the same index num _mag = _mags select _arrayNum; // Add mags before weapons so player doesn't need to reload to load in first mag _unit forceAddUniform _uniform; for "_i" from 1 to _randomno6 do {_unit addItemToUniform _mag;}; _unit addWeapon _weap; Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted May 1, 2016 Just use BIS_fnc_addWeapon. Cheers Share this post Link to post Share on other sites
Rydygier 1317 Posted May 1, 2016 Or, if you prefer rather your own piece of code than BIS function: _supportedMags = getArray (configFile >> "CfgWeapons" >> _weapons >> "magazines");//_supportedMags - array of supported magazines taken from weapon's config. _weapons - chosen weapon class _mag = _supportedMags select (floor (random (count _supportedMags)));//_mag - magazine type taken randomly from the array of the mags supported by chosen weapon It assumes, weapon class exists and has properly configured, not empty magazines array, which should be OK as long you base on handpicked weapons array, otherwise additional conditions needed, which roughly BIS_fnc_AddWeapon does + small bonuses like pointing primary muzzle name (redundant) but without internal mag randomization. 1 Share this post Link to post Share on other sites
soolie 189 Posted May 1, 2016 rydygier's way to get mags would be best if you want random mags Share this post Link to post Share on other sites
sinny 18 Posted May 2, 2016 Many many thanks! I loved and tried all your examples! This got the job done: _newGun = [_unit, _weapons, _randomno] call BIS_fnc_addWeapon; Share this post Link to post Share on other sites
serena 151 Posted May 3, 2016 This function return groupped by muzzle list of all magazines compatible with given weapon: Fn_Gear_CompatibleMagazines = { private _cls = configFile >> "CfgWeapons" >> _this; private _res = []; {_res pushBack (if (_x == "this") then {getArray(_cls >> "magazines")} else {getArray(_cls >> _x >> "magazines")}); } forEach getArray(_cls >> "muzzles"); _res }; For example: _myCompatibleMagazines = "arifle_MX_GL_ACO_F" call Fn_Gear_CompatibleMagazines; Result is: [ ["30Rnd_65x39_caseless_mag","30Rnd_65x39_caseless_mag_Tracer"], ["1Rnd_HE_Grenade_shell","UGL_FlareWhite_F","UGL_FlareGreen_F","UGL_FlareRed_F","UGL_FlareYellow_F","UGL_FlareCIR_F","1Rnd_Smoke_Grenade_shell","1Rnd_SmokeRed_Grenade_shell","1Rnd_SmokeGreen_Grenade_shell","1Rnd_SmokeYellow_Grenade_shell","1Rnd_SmokePurple_Grenade_shell","1Rnd_SmokeBlue_Grenade_shell","1Rnd_SmokeOrange_Grenade_shell","3Rnd_HE_Grenade_shell","3Rnd_UGL_FlareWhite_F","3Rnd_UGL_FlareGreen_F","3Rnd_UGL_FlareRed_F","3Rnd_UGL_FlareYellow_F","3Rnd_UGL_FlareCIR_F","3Rnd_Smoke_Grenade_shell","3Rnd_SmokeRed_Grenade_shell","3Rnd_SmokeGreen_Grenade_shell","3Rnd_SmokeYellow_Grenade_shell","3Rnd_SmokePurple_Grenade_shell","3Rnd_SmokeBlue_Grenade_shell","3Rnd_SmokeOrange_Grenade_shell"] ] 3 Share this post Link to post Share on other sites