Looks like it is “array overload day” today, so might as well share this useful function based on KK_fnc_assocArrayXXXX functions, which I have edited a little bit and added KK_fnc_assocArrayAllKeys, which is ultimately more useful function than KK_fnc_assocArraySize, which I removed.


KK_fnc_countUnique = { //_cnt = [_ref, _key] call KK_fnc_countUnique private ["_ref","_key","_cnt"]; _ref = _this select 0; _key = _this select 1; _cnt = [_ref, _key] call KK_fnc_assocArrayGetVal; _cnt = if (isNil {_cnt}) then [{1},{_cnt + 1}]; [_ref, _key, _cnt] call KK_fnc_assocArrayAddKeyVal; _cnt };

This function is designed to count unique keys every time you call it. It also returns current count for the key as it is counted, that is if you need immediate feedback. I personally used associative arrays for this purpose in other languages many many times and the lack of associative array handling in Arma is limiting. As an example I will demonstrate how easy it is to keep track of how many of which ammo was fired by the player. Make sure you have KK_fnc_assocArrayXXXX function initialised, as KK_fnc_countUnique is based on them.

So instead of creating a random associative array, I will name one so that I can refer to it easily when needed. Let’s call it “AmmoStats”. This will be the reference string. The best way to keep record of the fired ammo is of course from the “Fired” Event Handler:

player addEventHandler ["Fired", { 0 = ["AmmoStats", _this select 4] call KK_fnc_countUnique; }];

This will create and add fired ammo to stats in the array reference by “AmmoStats”. I also want to be able to see the stats with a scroll of a mouse. I need some kind of routine that will go through every key of the associative array (every type of ammo fired) and list corresponding value stored in the array:

player addAction ["Show Ammo Stats", { _hint = "-- Ammo / Times Fired --\n"; { _hint = _hint + format [ "%1 / %2", _x, ["AmmoStats", _x] call KK_fnc_assocArrayGetVal ] + "\n"; } forEach ("AmmoStats" call KK_fnc_assocArrayAllKeys); hint _hint; }];

And this is the result: