tortuosit 486 Posted July 26, 2016 Hi guys, I was just writing a small script which adds a random weapon/ammo to my (single) player at mission init. Just for fun. I love to save game logics which I can easily drop into the editor later for quick usage. For the curious: ARGS: 1st arg: prob. of heavy weapon, 2nd min magazines count, 3rd max mags, 4th: allow mixed mags, 5th: loaded mag may not be full 0 = [0.1, 2, 4, true, true] spawn { waituntil {alive player}; private ["_wArray", "_select", "_mag", "_num", "_curr"]; if ((random 1) < (_this select 0)) then { _wArray = [ ["arifle_Mk20_F"], ["arifle_MXC_ACO_F"], ["arifle_MXM_RCO_pointer_snds_F"], ["arifle_Katiba_F"], ["arifle_Katiba_C_F"], ["arifle_Katiba_GL_F"], ["arifle_Katiba_C_ACO_pointer_F"], ["arifle_Katiba_GL_ACO_F"], ["arifle_Mk20_GL_plain_F"], ["arifle_Mk20C_ACO_F"], ["arifle_MX_GL_ACO_pointer_F"], ["arifle_MXC_Holo_F"], ["arifle_MXC_ACO_pointer_snds_F"], ["srifle_DMR_01_F"], ["srifle_DMR_01_ACO_F"], ["srifle_DMR_01_MRCO_F"], ["srifle_DMR_01_SOS_F"], ["srifle_DMR_01_DMS_F"], ["srifle_DMR_01_DMS_snds_F"], ["srifle_DMR_01_ARCO_F"], ["srifle_EBR_F"], ["srifle_EBR_ACO_F"], ["srifle_EBR_MRCO_pointer_F"], ["srifle_EBR_ARCO_pointer_snds_F"], ["srifle_EBR_SOS_F"], ["srifle_EBR_ARCO_pointer_snds_F"], ["srifle_EBR_DMS_F"], ["srifle_EBR_Hamr_pointer_F"], ["srifle_EBR_DMS_pointer_snds_F"], ["srifle_GM6_F"], ["srifle_GM6_SOS_F"], ["srifle_GM6_LRPS_F"], ["srifle_LRR_F"], ["srifle_LRR_SOS_F"], ["srifle_LRR_LRPS_F"], ["LMG_Mk200_F"], ["LMG_Mk200_MRCO_F"], ["LMG_Mk200_pointer_F"], ["LMG_Zafir_F"], ["LMG_Zafir_pointer_F"], ["LMG_Zafir_ARCO_F"], ["arifle_SDAR_F"], ["arifle_TRG20_F"], ["arifle_TRG21_GL_ACO_pointer_F"], ["SMG_01_Holo_pointer_snds_F"], ["srifle_DMR_02_sniper_AMS_LP_S_F"], ["srifle_DMR_03_multicam_F"], ["srifle_DMR_04_MRCO_F"], ["srifle_DMR_05_SOS_F"], ["srifle_DMR_06_camo_khs_F"], ["MMG_01_tan_F"], ["MMG_02_black_RCO_BI_F"], ["srifle_GM6_ghex_F"], ["arifle_AK12_F"], ["arifle_AKM_F"], ["arifle_AKS_F"], ["arifle_CTAR_blk_F"], ["srifle_DMR_07_ghex_F"], ["LMG_03_F"], ["srifle_LRR_tna_F"], ["SMG_05_F"], ["arifle_SPAR_01_khk_F"], ["arifle_SPAR_02_khk_F"], ["arifle_SPAR_03_khk_F"], ["arifle_ARX_ghex_F"] ]; } else { _wArray = [ ["hgun_P07_F"], ["hgun_P07_snds_F"], ["hgun_Pistol_heavy_01_F"], ["hgun_Pistol_heavy_01_snds_F"], ["hgun_Pistol_heavy_01_MRD_F"], ["hgun_Pistol_heavy_02_F"], ["hgun_Pistol_heavy_02_Yorris_F"], ["hgun_Rook40_F"], ["hgun_Rook40_snds_F"], ["hgun_ACPC2_F"], ["hgun_ACPC2_snds_F"], ["hgun_P07_khk_F"], ["hgun_Pistol_01_F"] ]; }; _select = _wArray select floor(random(count _wArray)); if ((count _select) == 1) then { _select = _select + getArray (configFile >> "cfgWeapons" >> (_select select 0) >> "magazines"); }; _mag = 1 + floor(random((count _select) - 1)); _num = (_this select 1) + round(random ((_this select 2) - (_this select 1))); removeAllWeapons player; if (_num > 0) then { for "_i" from 1 to _num do { player addMagazine (_select select _mag); if (_this select 3) then {_mag = 1 + floor(random((count _select) - 1))}; }; }; player addWeapon (_select select 0); if ((_this select 4) && (_num > 0)) then { _curr = player ammo currentWeapon player; player setAmmo [currentWeapon player, 1 + floor(random(_curr))]; }; }; So now I wonder if I could automatically get an array of all available sidearms (maybe also heavy weapons or other... classes). I look for instance into "configfile >> "CfgWeapons" >> "hgun_ACPC2_F" - is there any property that all sidearmshave in common? I do not see it... I mean there must be something, because Arsenal can distinguish between heavy guns and sidearms. Ideas? I'm not experienced with this. In the script I already auto retrieve the allowed ammo for the chosen weapon. It's a bit über complicated because if you add specific ammo to the weapons in the array, it will choose that ammo. TIA Share this post Link to post Share on other sites
tortuosit 486 Posted July 26, 2016 This guy has a solution: https://www.youtube.com/watch?v=Qpu33XEycEs Share this post Link to post Share on other sites
pedeathtrian 99 Posted July 26, 2016 Instead of getting parents for every you can use isKindOf (it's more effective than BIS_fnc_returnParents): if (_className isKindOf ["Pistol", configFile >> "CfgWeapons"]) then { // ... } or getting all pistol configs at once: _pistolConfigs = "((configName (_x)) isKindof ['Pistol', configFile >> 'cfgWeapons']) && (getText (_x >> 'displayName') != '')" configClasses (configFile >> "cfgWeapons"); Another approach is to check "cursor" property of weapon class, which could be "hgun", "arifle", "srifle", "mg", "missile", "rocket", "", "EmptyCursor" (and probably others). This way you can tell rifles from machineguns for example or sniper rifle from assault one. Share this post Link to post Share on other sites
tortuosit 486 Posted July 26, 2016 Thanks pedeathtrian, not yet used your changes. A quick and dirty working instance (without your recommendation) is this: 0 = [0.1, 2, 4, true, true] spawn { waituntil {alive player}; private ["_cfgWeapons", "_weaponString", "_weaponArray", "_magazines_array", "_type", "_selectedWeapon", "_magType", "_magNum", "_curr"]; _cfgWeapons = "true" configClasses (configFile >> "cfgWeapons"); _weaponArray = []; if ((random 1) < (_this select 0)) then {_type = "Rifle"} else {_type = "Pistol"}; { _weaponString = configName (_x); _parents = [_x,true] call BIS_fnc_returnParents; if (_type in _parents) then {_weaponArray append [_weaponString];}; } forEach _cfgWeapons; _selectedWeapon = _weaponArray select floor(random(count _weaponArray)); _magazines_array = getArray (configFile >> "cfgWeapons" >> _selectedWeapon >> "magazines"); _magType = floor(random((count _magazines_array) - 1)); _magNum = (_this select 1) + round(random ((_this select 2) - (_this select 1))); removeAllWeapons player; if (_magNum > 0) then { for "_i" from 1 to _magNum do { player addMagazine (_magazines_array select _magType); if (_this select 3) then {_magType = floor(random((count _magazines_array) - 1))}; }; }; player addWeapon _selectedWeapon; if ((_this select 4) && (_magNum > 0)) then { _curr = player ammo currentWeapon player; player setAmmo [currentWeapon player, 1 + floor(random(_curr))]; }; }; Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted July 26, 2016 _pistols = "getnumber (_x >> 'type') isEqualTo 2 AND getnumber (_x >> 'scope') isEqualTo 2" configClasses (configfile >> 'CfgWeapons'); I'm also filtering for ammo damage but this should do the trick aswell. Runs at 8ms, twice as fast when compared to pedeathtrians solution. This only matters if you call it more than once per mission, best run it once at mission start and declare it in a global variable for performance reasons. Just saw that code monster of yours. At least replace addmagazine addweapon with BIS_fnc_addWeapon. Cheers 1 Share this post Link to post Share on other sites
pedeathtrian 99 Posted July 26, 2016 _pistols = "getnumber (_x >> 'type') isEqualTo 2 AND getnumber (_x >> 'scope') isEqualTo 2" configClasses (configfile >> 'CfgWeapons'); Whoa, that's much better. Where can I find values for this 'type' property? Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted July 26, 2016 Whoa, that's much better. Where can I find values for this 'type' property? CfgWeapons_Config_Reference and a bit of tinkering. Cheers Share this post Link to post Share on other sites
soolie 189 Posted July 26, 2016 You can find the type values in the config viewer (cfgWeapons >> classname >> "type") Some items, like hats uniforms and vests have type number under (cfgWeapons >> classname >> "itemInfo" >> "type") Here's some code putting all gear into different arrays. Learned how to do this from Dslyecxi's gear selector so props to him! LoadGearLists = { _hats = []; _uniforms = []; _vests = []; _primaries = []; _secondaries = []; _launchers = []; _backpacks = []; _glasses = []; _faces = []; _count = count (configFile >> "CfgWeapons"); for "_x" from 0 to (_count-1) do { _weap = ((configFile >> "CfgWeapons") select _x); if (isClass _weap) then { if (getnumber (_weap >> "scope") == 2) then { if (isClass (_weap >> "ItemInfo")) then { _infoType = (getnumber (_weap >> "ItemInfo" >> "Type")); switch (_infoType) do { case 605: {_hats = _hats + [configName _weap];}; case 801: {_uniforms = _uniforms + [configName _weap];}; case 701: {_vests = _vests + [configName _weap];}; }; }; if (!isClass (_weap >> "LinkedItems")) then { if (count(getarray (_weap >> "magazines")) !=0 ) then { _type = getnumber (_weap >> "type"); if (_type == 1) then {_primaries = _primaries + [configName _weap];} else { if (_type == 2) then {_secondaries = _secondaries + [configName _weap];} else { if (_type == 4) then {_launchers = _launchers + [configName _weap];} }; }; }; }; }; }; }; _count = count (configFile >> "CfgVehicles"); for "_x" from 0 to (_count-1) do { _item=((configFile >> "CfgVehicles") select _x); if (isClass _item) then { if (getnumber (_item >> "scope") == 2) then { if (gettext (_item >> "vehicleClass") == "Backpacks") then { _backpacks = _backpacks + [configname _item] }; }; }; }; _count = count (configFile >> "CfgGlasses"); for "_x" from 0 to (_count-1) do { _item=((configFile >> "CfgGlasses") select _x); if (isClass _item) then { if (getnumber (_item >> "scope") == 2) then {_glasses = _glasses + [configName _item];}; }; }; _count = count (configFile >> "CfgFaces" >> "Man_A3"); for "_x" from 0 to (_count-1) do { _item=((configFile >> "CfgFaces" >> "Man_A3") select _x); if (isClass _item) then {_faces = _faces + [configName _item];}; }; List_Hats = [] + _hats; List_Uniforms = [] + _uniforms; List_Vests = [] + _vests; List_Primaries = [] + _primaries; List_Secondaries = [] + _secondaries; List_Launchers = [] + _launchers; List_Backpacks = [] + _backpacks; List_Glasses = [] + _glasses; List_Faces = [] + _faces; List_AllWeapons = List_Primaries + List_Secondaries + List_Launchers; }; 1 1 Share this post Link to post Share on other sites
pedeathtrian 99 Posted July 26, 2016 CfgWeapons_Config_Reference and a bit of tinkering. Cheers Tinkering. Tinkering everywhere :) Unfortunately there's absolutely no explanation of what Type field is and what values it can take. Something like side has. Intead all these magic constants we have. If there were a list of possible values I would have used it in the first place since I visited this page before posting in this thread, and the best I found (apparently didn't search too good) was displayName coupled with filtering by isKindOf. But thanks anyway. Share this post Link to post Share on other sites
tortuosit 486 Posted July 27, 2016 Runs at 8ms, twice as fast when compared to pedeathtrians solution.I'm just running it at mission start only, but will use your optimizations... Because: I've put the beauty which you called "code monster" ;) into the debug window for execution and realized, with a few weapon mods loaded it takes >5 seconds until the player changes weapon. So optimization is worth it. Also because of the tinkering fun :) Interesting things I learn about performance. isEqualTo for instance. Guys, btw, for random ranges with even distribution, do you still use the a+random(b-a) method or the new random arrays. I must say I am usually to lazy to do performance testing with big loops... because all the code tinkering takes enough of time. It's all about gut instincts. and declare it in a global variable for performance reasons.Hold on. I guess you mention it in case I would use the script repeatedly in mission... Or are you saying operations on local variables are slower? Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted July 27, 2016 I'm just running it at mission start only, but will use your optimizations... Because: I've put the beauty which you called "code monster" ;) into the debug window for execution and realized, with a few weapon mods loaded it takes >5 seconds until the player changes weapon. So optimization is worth it. Also because of the tinkering fun :) Interesting things I learn about performance. isEqualTo for instance. Guys, btw, for random ranges with even distribution, do you still use the a+random(b-a) method or the new random arrays. I must say I am usually to lazy to do performance testing with big loops... because all the code tinkering takes enough of time. It's all about gut instincts. Hold on. I guess you mention it in case I would use the script repeatedly in mission... Or are you saying operations on local variables are slower? Your best bet would be to set up a function in description.ext and use the preInit = 1 attribute, so it's already defined before the mission starts. This is always good practice, especially for stuff that takes time to execute and is expensive in calculations. Also the code you posted from dyswhatever is heavily outdated, there are many new script commands out there that can be put to good use, like configClasses, pushBack or isEqualTo, which you already mentioned. It runs fast at least, 0.0021 ms. The new random array is putting out gauss normal distribution, the so called gauss bell. It's not an even distribution. random [5,10,15] will rarely return values close to 5 or 15, but most of the time they will be close to 10. Performance testing only needs one click of a button in SP editor. Unfortunately diag_codePerformance doesn't work in MP at all for some reason. Gut instincts can lead you to wrong places regarding code performance, I've been there. Regarding local/global variables there's no speed difference from what I've seen, unless you start broadcasting to all clients. Tinkering. Tinkering everywhere :) Unfortunately there's absolutely no explanation of what Type field is and what values it can take. Something like side has. Intead all these magic constants we have. If there were a list of possible values I would have used it in the first place since I visited this page before posting in this thread, and the best I found (apparently didn't search too good) was displayName coupled with filtering by isKindOf. But thanks anyway. Yeah, type is one of these weird values. Rifles are 1, pistols 2 and launchers are 4, while binoculars, helmets and scopes are 130172. The mine detector is also 4. Makes me scratch my head, but works for rifles and pistols reliably at least. Cheers Share this post Link to post Share on other sites
tortuosit 486 Posted July 27, 2016 The new random array is putting out gauss normal distributionAh thanks for the reminder, I thought it was linear distrib with 2 args and gauss bell with 3 args (hey you don't need to explain gaussian bell etc. to me). But there is no 2 arg variant I think... it was my own function I wrote :) Someone else posted the dslyexcy code. 1 Share this post Link to post Share on other sites
tortuosit 486 Posted July 27, 2016 I ended up with those - it's indeed wayyyyy faster than above with BIS_fnc_returnParents: Random weapon from complete weapon list: 0 = [0.2, 2, 4, true, true] spawn { waituntil {alive player}; private ["_cfgWeapons", "_weaponString", "_weaponArray", "_magazines_array", "_type", "_selectedWeapon", "_magType", "_magCount"]; _cfgWeapons = "true" configClasses (configFile >> "cfgWeapons"); _weaponArray = []; if ((random 1) < (_this select 0)) then { _cfgWeapons = "getnumber (_x >> 'type') isEqualTo 1 AND getnumber (_x >> 'scope') isEqualTo 2" configClasses (configfile >> 'CfgWeapons');} else { _cfgWeapons = "getnumber (_x >> 'type') isEqualTo 2 AND getnumber (_x >> 'scope') isEqualTo 2" configClasses (configfile >> 'CfgWeapons'); }; { _weaponString = configName (_x); _weaponArray append [_weaponString]; } forEach _cfgWeapons; _selectedWeapon = _weaponArray select floor(random(count _weaponArray)); _magazines_array = getArray (configFile >> "cfgWeapons" >> _selectedWeapon >> "magazines"); _magType = floor(random((count _magazines_array) - 1)); _magCount = (_this select 1) + round(random ((_this select 2) - (_this select 1))); removeAllWeapons player; if (_magCount > 0) then { for "_i" from 1 to _magCount do { player addMagazine (_magazines_array select _magType); if (_this select 3) then {_magType = floor(random((count _magazines_array) - 1))}; }; }; player addWeapon _selectedWeapon; if ((_this select 4) && (_magCount > 0)) then { player setAmmo [currentWeapon player, 1 + floor(random(player ammo currentWeapon player))]; }; }; Random weapon from user weapon list: 0 = [0.5, 2, 4, true, true] spawn { waituntil {alive player}; private ["_weaponArray", "_magazines_array", "_selectedWeapon", "_selectedWeaponType", "_magType", "_magCount"]; if ((random 1) < (_this select 0)) then { _weaponArray = [ ["arifle_AK12_F","arifle_AK12_GL_F"], ["arifle_AKM_F"], ["arifle_AKS_F"], ["arifle_CTAR_blk_F","arifle_CTAR_GL_blk_F","arifle_CTARS_blk_F"], ["srifle_DMR_07_ghex_F","srifle_DMR_07_blk_F","srifle_DMR_07_hex_F"], ["srifle_GM6_ghex_F"], ["LMG_03_F"], ["srifle_LRR_tna_F"], ["arifle_MX_GL_khk_F","arifle_MX_khk_F","arifle_MX_SW_khk_F"], ["arifle_MXC_khk_F"], ["arifle_MXM_khk_F"], ["SMG_05_F"], ["arifle_SPAR_01_khk_F","arifle_SPAR_01_snd_F","arifle_SPAR_01_blk_F"], ["arifle_SPAR_02_khk_F","arifle_SPAR_02_snd_F","arifle_SPAR_02_blk_F"], ["arifle_SPAR_03_khk_F","arifle_SPAR_03_snd_F","arifle_SPAR_03_blk_F"], ["arifle_ARX_ghex_F","arifle_ARX_blk_F","arifle_ARX_hex_F"] ]; } else { _weaponArray = [ ["hgun_Pistol_01_F"], ["hgun_P07_F","hgun_P07_khk_F"], ["hgun_ACPC2_F"], ["hgun_Pistol_heavy_01_F"], ["hgun_Pistol_heavy_02_F", "hgun_Pistol_heavy_02_Yorris_F"], ["hgun_Rook40_F"] ]; }; _selectedWeaponType = _weaponArray select floor(random(count _weaponArray)); _selectedWeapon = _selectedWeaponType select floor(random(count _selectedWeaponType)); _magazines_array = getArray (configFile >> "cfgWeapons" >> _selectedWeapon >> "magazines"); _magType = floor(random(count _magazines_array)); _magCount = (_this select 1) + round(random ((_this select 2) - (_this select 1))); removeAllWeapons player; if (_magCount > 0) then { for "_i" from 1 to _magCount do { player addMagazine (_magazines_array select _magType); if (_this select 3) then {_magType = floor(random(count _magazines_array))}; }; }; player addWeapon _selectedWeapon; if ((_this select 4) && (_magCount > 0)) then { player setAmmo [currentWeapon player, 1 + floor(random(player ammo currentWeapon player))]; }; }; Did not use BIS_fnc_addWeapon because I want to optionally have mixed mags. No description.ext things because it's just about quick editor missions and dropping game logics on map. Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted July 27, 2016 Why this line though? _weaponArray append [_weaponString]; Use this: _weaponArray pushBack _weaponString; does the same faster. BIS_fnc_addWeapon can add any magazine that's compatible with the weapon. Cheers 1 Share this post Link to post Share on other sites
tortuosit 486 Posted July 28, 2016 _pistols = "getnumber (_x >> 'type') isEqualTo 2 AND getnumber (_x >> 'scope') isEqualTo 2" configClasses (configfile >> 'CfgWeapons'); Can you tell why you check for scope==2? Just a preference or does it maybe filter some bad results out? Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted July 28, 2016 scope = 2 basically means the object can be used in game with an image in the inventory. scope = 1 means it can be used but has no image in the inventory. scope = 0 probably are base classes. Cheers 1 Share this post Link to post Share on other sites
Larrow 2822 Posted July 29, 2016 Unfortunately there's absolutely no explanation of what Type field is and what values it can take //>> "Type" #define WeaponSlotPrimary 1 #define WeaponSlotHandGun 2 #define WeaponSlotSecondary 4 #define WeaponSlotHandGunItem 16 #define WeaponSlotItem 256 #define WeaponSlotBinocular 4096 #define WeaponHardMounted 65536 #define WeaponSlotInventory 131072 //>> "ItemInfo" >> "type" #define DEFAULT_SLOT 0 #define MUZZLE_SLOT 101 #define OPTICS_SLOT 201 #define FLASHLIGHT_SLOT 301 #define BIPOD_SLOT 302 #define FIRSTAIDKIT_SLOT 401 #define FINS_SLOT 501 #define BREATHINGBOMB_SLOT 601 #define NVG_SLOT 602 #define GOGGLE_SLOT 603 #define SCUBA_SLOT 604 #define HEADGEAR_SLOT 605 #define FACTOR_SLOT 607 #define RADIO_SLOT 611 #define HMD_SLOT 616 #define BINOCULAR_SLOT 617 #define MEDIKIT_SLOT 619 #define TOOLKIT_SLOT 620 //added #define VEST_SLOT 701 #define UNIFORM_SLOT 801 #define BACKPACK_SLOT 901 6 Share this post Link to post Share on other sites
pedeathtrian 99 Posted July 29, 2016 Larrow, thank you very very much, sir! Share this post Link to post Share on other sites
533dk 10 Posted August 8, 2016 I ended up with those - it's indeed wayyyyy faster than above with BIS_fnc_returnParents: Random weapon from complete weapon list: 0 = [0.2, 2, 4, true, true] spawn { waituntil {alive player}; private ["_cfgWeapons", "_weaponString", "_weaponArray", "_magazines_array", "_type", "_selectedWeapon", "_magType", "_magCount"]; _cfgWeapons = "true" configClasses (configFile >> "cfgWeapons"); _weaponArray = []; if ((random 1) < (_this select 0)) then { _cfgWeapons = "getnumber (_x >> 'type') isEqualTo 1 AND getnumber (_x >> 'scope') isEqualTo 2" configClasses (configfile >> 'CfgWeapons');} else { _cfgWeapons = "getnumber (_x >> 'type') isEqualTo 2 AND getnumber (_x >> 'scope') isEqualTo 2" configClasses (configfile >> 'CfgWeapons'); }; { _weaponString = configName (_x); _weaponArray append [_weaponString]; } forEach _cfgWeapons; _selectedWeapon = _weaponArray select floor(random(count _weaponArray)); _magazines_array = getArray (configFile >> "cfgWeapons" >> _selectedWeapon >> "magazines"); _magType = floor(random((count _magazines_array) - 1)); _magCount = (_this select 1) + round(random ((_this select 2) - (_this select 1))); removeAllWeapons player; if (_magCount > 0) then { for "_i" from 1 to _magCount do { player addMagazine (_magazines_array select _magType); if (_this select 3) then {_magType = floor(random((count _magazines_array) - 1))}; }; }; player addWeapon _selectedWeapon; if ((_this select 4) && (_magCount > 0)) then { player setAmmo [currentWeapon player, 1 + floor(random(player ammo currentWeapon player))]; }; }; Random weapon from user weapon list: 0 = [0.5, 2, 4, true, true] spawn { waituntil {alive player}; private ["_weaponArray", "_magazines_array", "_selectedWeapon", "_selectedWeaponType", "_magType", "_magCount"]; if ((random 1) < (_this select 0)) then { _weaponArray = [ ["arifle_AK12_F","arifle_AK12_GL_F"], ["arifle_AKM_F"], ["arifle_AKS_F"], ["arifle_CTAR_blk_F","arifle_CTAR_GL_blk_F","arifle_CTARS_blk_F"], ["srifle_DMR_07_ghex_F","srifle_DMR_07_blk_F","srifle_DMR_07_hex_F"], ["srifle_GM6_ghex_F"], ["LMG_03_F"], ["srifle_LRR_tna_F"], ["arifle_MX_GL_khk_F","arifle_MX_khk_F","arifle_MX_SW_khk_F"], ["arifle_MXC_khk_F"], ["arifle_MXM_khk_F"], ["SMG_05_F"], ["arifle_SPAR_01_khk_F","arifle_SPAR_01_snd_F","arifle_SPAR_01_blk_F"], ["arifle_SPAR_02_khk_F","arifle_SPAR_02_snd_F","arifle_SPAR_02_blk_F"], ["arifle_SPAR_03_khk_F","arifle_SPAR_03_snd_F","arifle_SPAR_03_blk_F"], ["arifle_ARX_ghex_F","arifle_ARX_blk_F","arifle_ARX_hex_F"] ]; } else { _weaponArray = [ ["hgun_Pistol_01_F"], ["hgun_P07_F","hgun_P07_khk_F"], ["hgun_ACPC2_F"], ["hgun_Pistol_heavy_01_F"], ["hgun_Pistol_heavy_02_F", "hgun_Pistol_heavy_02_Yorris_F"], ["hgun_Rook40_F"] ]; }; _selectedWeaponType = _weaponArray select floor(random(count _weaponArray)); _selectedWeapon = _selectedWeaponType select floor(random(count _selectedWeaponType)); _magazines_array = getArray (configFile >> "cfgWeapons" >> _selectedWeapon >> "magazines"); _magType = floor(random(count _magazines_array)); _magCount = (_this select 1) + round(random ((_this select 2) - (_this select 1))); removeAllWeapons player; if (_magCount > 0) then { for "_i" from 1 to _magCount do { player addMagazine (_magazines_array select _magType); if (_this select 3) then {_magType = floor(random(count _magazines_array))}; }; }; player addWeapon _selectedWeapon; if ((_this select 4) && (_magCount > 0)) then { player setAmmo [currentWeapon player, 1 + floor(random(player ammo currentWeapon player))]; }; }; Did not use BIS_fnc_addWeapon because I want to optionally have mixed mags. No description.ext things because it's just about quick editor missions and dropping game logics on map. Im having some issues using the first script. I basically want to find the classnames for all rifles. So i commented out the lines where you find handguns. But when i copy my array it shows alot of different classnames, eg uniforms and nvg's. 0 = [0.2, 2, 4, true, true] spawn { waituntil {alive player}; private ["_cfgWeapons", "_weaponString", "_weaponArray"]; _cfgWeapons = "true" configClasses (configFile >> "cfgWeapons"); _weaponArray = []; if ((random 1) < (_this select 0)) then { _cfgWeapons = "getnumber (_x >> 'type') isEqualTo 1 AND getnumber (_x >> 'scope') isEqualTo 2" configClasses (configfile >> 'CfgWeapons');}; /*else { _cfgWeapons = "getnumber (_x >> 'type') isEqualTo 2 AND getnumber (_x >> 'scope') isEqualTo 2" configClasses (configfile >> 'CfgWeapons'); };*/ { _weaponString = configName (_x); _weaponArray pushBack [_weaponString]; } forEach _cfgWeapons; copyToClipboard format["%1",_weaponArray]; Share this post Link to post Share on other sites
Larrow 2822 Posted August 8, 2016 All rifles? or all primary weapons? Take your pick.. _allPrimaryWeapons = "getNumber( _x >> 'scope' ) isEqualTo 2 && { getNumber( _x >> 'type' ) isEqualTo 1 }"configClasses( configFile >> "CfgWeapons" ) apply { configName _x }; _allRifles = "getNumber( _x >> 'scope' ) isEqualTo 2 && { getNumber( _x >> 'type' ) isEqualTo 1 && getText( _x >> 'cursor' ) == 'arifle' }"configClasses( configFile >> "CfgWeapons" ) apply { configName _x }; 4 Share this post Link to post Share on other sites
tortuosit 486 Posted August 10, 2016 Yeah nice. I'm using ... AND getText( _x >> 'author' ) == 'Bohemia Interactive' at some point to filter for vanilla only... Share this post Link to post Share on other sites
yacobmate 2 Posted August 10, 2016 I'd also recommend watching the video the first comment provided Share this post Link to post Share on other sites