jsmith82 0 Posted February 25 Hi all, I'm stumped. Looking to count bullets in my inventory that are not equipped to the primary, secondary or handgun weapon - essentially what is in the uniform, vest and backpack if applicable. All items have a built in command that can be called / checked: uniformMagazines, vestMagazines, backpackMagazines. Any return is an array with 2 items: Name of mag, ammo in mag. So I know I need to loop through each mag within each of the 3 places to check, take the second item returned in the array and add it to a variable. This is where I'm erroring left and right, I can't figure it out. Really would appreciate a nudge in the right direction. To test, I'm just trying to count ammo in my uniform. The rest will add on later once I know what works. Here is my current: private _count = 0; {_count = _count + (_x select 2;)} forEach uniformMagazines player; Thanks in advance for any help provided. Share this post Link to post Share on other sites
Harzach 2517 Posted February 25 Those commands return an array that holds only a string. The info you want is embedded in that string, and can be tricky to extract. Example from the wiki: [ "6.5mm 30Rnd STANAG Mag(30/30)[id/cr:1/0](3x)" ] An easier route might be magazinesAmmoFull, which returns a multidimensional array of all magazines, including some very useful parameters. If we filter the array for unloaded magazines only, we skip counting loaded mags and other mag types like throwables. Then we just grab the ammo count parameter and add it to the pool. private _rounds = 0; magazinesAmmoFull player select { (_x #3 == -1) } apply { _rounds = _rounds + _x #1 }; hint str _rounds; Keep in mind that this results in a single number that includes all varieties of bullets. Share this post Link to post Share on other sites
mrcurry 505 Posted February 25 1 hour ago, jsmith82 said: private _count = 0; {_count = _count + (_x select 2;)} forEach uniformMagazines player; You're not that far off. 🙂 Firstly you have a misplaced semicolon inside the parentheses. The grammar is: Semicolon ends the statement and all round brackets (i.e. parentheses) needs to be "closed" before the end of the statement. Just don't mistake round brackets () with curly brackets {}. Secondly uniformMagazines et. al. return an array of strings so your _x select 2 just gets the 3rd (yes 3rd, 0 is the 1st) character in what happens to be the mag's name. No Bueno! To fix this without string-magic you can just use: magazinesAmmo player This command gets the data in the format you expect with the added bonus of getting uniform, vest and backpack in one go while ignoring loaded mags. If you needed more nudges just ask. Edit: Dammit @Harzach! 😛 1 Share this post Link to post Share on other sites
jsmith82 0 Posted February 26 23 hours ago, Harzach said: private _rounds = 0; magazinesAmmoFull player select { (_x #3 == -1) } apply { _rounds = _rounds + _x #1 }; hint str _rounds; Thank you both for the replies! Harzach, your code is a really cool approach to a sum if / for each that I have not used before and thank you for sharing! It is working as you intended, counting bullets in the inventory that are sitting in a clip. What's interesting is if a gun is loaded and in my inventory but not equipped, those bullets are not counted. I feel after looking at the command you suggested I can tweak the checks to get the results I want and will share that here (good or bad). Appreciate the help! Share this post Link to post Share on other sites
jsmith82 0 Posted February 27 @Harzach - question for you. Last night I spent a few hours setting the different variables of magazinesAmmoFull trying to get a count of total ammo if the gun(s) is/are loaded, in inventory but not equipped. I played with currentMuzzle, location in general and arg 2. Argument #2 seems like it should be that check, is the ammo loaded in a gun, but altering the check to the following doesn’t error out but also doesn’t return results: (_x #2 == True && _x #3 == -1) Above seemed redundant, given the status of arg 3 so I thought the following was surely a lock but this also did not turn results (tested using a loaded handgun in my uniform): (_x #2 == True && _x #3 == 2) also…. (_x #2 == True && _x #3 == 2 && _x #4 == “Uniform”) I guess I’m misinterpreting what argument 2 is meant for? Or perhaps at the point the ammo is loaded it’s no longer considered ammo so a different approach will have to be taken. Kind of chasing my tail with their description. Is it possible to get a count of ammo, loaded in any gun, but only for guns that are unequipped using this command? #0: String: magazine class name #1: Number: magazine ammo count #2: Boolean: is magazine loaded #3: Number: magazine type: -1 = n/a (default if magazine is not loaded) 0 - grenade 1 - primary weapon mag 2 - handgun mag 4 - secondary weapon mag 4096 - binocular weapon mag 65536 - vehicle mag #4: String: magazine location: "Vest", "Uniform", "Backpack", "" or currentMuzzle if the magazine is loaded Share this post Link to post Share on other sites
Harzach 2517 Posted February 27 Best I can figure at the moment is all mags in inventory, plus any loaded mags in unequipped weapons - NOT including any weapons you may have in your backpack/vest/uniform. That might take some other voodoo. private _rounds = 0; magazinesAmmoFull player select { (_x #3 == -1 || (_x #2 == true && _x #4 != currentMuzzle player)) } apply { _rounds = _rounds + _x #1 }; hintSilent str _rounds; So if you have your primary equipped, this will skip that mag, but will include the mags in your handgun and secondary. Share this post Link to post Share on other sites
jsmith82 0 Posted February 28 Interesting observation. I placed only the following code on my player so I could see what is showing up for the handgun in inventory: hint str magazinesAmmoFull player; Loaded guns don’t show up. I took a 6P53 and a clip, put it in my uniform. I could see the string information for the clip. I loaded the clip into the gun, popped the gun in my uniform, the hint disappeared. Just a couple of empty brackets: [] {if (_x isKindOf [‘Pistol’, configFile >> ‘CfgWeapons’]) then {count = count + 1;}} forEach uniformItems player; ^^this counts handguns in the inventory, so I’m feeling like the solution could be count = count + (figure out the ammo in _x). As is tradition, errors everywhere so far but I’m still working at it! Edit: I’m wrong. I hinted _x, it’s only the name of the weapon and has no actual information about the ammo IN the weapon. It’s a lone string. Bummer. Share this post Link to post Share on other sites