scottb613 285 Posted September 16, 2022 Hi Folks, Working on a routine to display a unit's health and ammo status for the player group - so potentially a 20-line report of text for the largest player groups. I've tested [hint] and it works with 20 lines of text and does support carriage returns - [format] doesn't seem to. So - I've got a loop running to gather all the required information for each unit and I was thinking of putting each line into an array - then outputting in some yet undefined manner. Question: I need to make a 20-line formatted text report with carriage returns for a [hint] - based on the gathered information. Any thoughts on how I can do this? I tried the [sideChat] but that only displays half a dozen lines or so max. Where I'm at: private _unitArr = units player; _unitArr deleteAt 0; private _hintArr = []; if (isnil "kiaCnt") then { kiaCnt = 0; }; { private _unit = _x; private _health = round ((1 - damage _unit) * 100); // health in % from 0 to 100 private _kiaCnt = kiaCnt; //If Dead - Remove From Group - Increment Kill Counter if (_health == 0) then { kiaCnt = _kiaCnt + 1; private _grpDOA = createGroup [west, true]; [_unit] join _grpDOA; }; //Unit Info private _priWeap = primaryWeapon _unit; private _unitMagArr = magazines _unit; private _compMagArr = compatibleMagazines _priWeap; private _cntMag = 0; // Count Primary Weapon Magazines { private _compMag = _x; { private _unitMag = _x; if (_compMag == _unitMag) then {_cntMag = _cntMag + 1}; } foreach _unitMagArr; } foreach _compMagArr; private _logger = format ["%1 || %2 || %3 || Mags: %4", _unit, _health, _priWeap, _cntMag]; _hintArr pushback _logger; _unit groupChat _logger; } foreach _unitArr; _logger = format ["KIA: %1", kiaCnt]; player groupChat _logger; Thanks. Regards, Scott Share this post Link to post Share on other sites
Harzach 2518 Posted September 16, 2022 Check out parseText 1 Share this post Link to post Share on other sites
scottb613 285 Posted September 16, 2022 On 9/16/2022 at 1:23 PM, Harzach said: Check out parseText Thank you - kindly. I'll take a gander. Regards, Scott Share this post Link to post Share on other sites
Ibragim A 163 Posted September 16, 2022 System chat is a bad idea for you. Use the usual hint + parseText as already stated instead: private _unitArr = units player; _unitArr deleteAt 0; private _hintStr = ""; if (isnil "kiaCnt") then { kiaCnt = 0; }; { private _unit = _x; private _health = round ((1 - damage _unit) * 100); // health in % from 0 to 100 private _kiaCnt = kiaCnt; //If Dead - Remove From Group - Increment Kill Counter if (_health == 0) then { kiaCnt = _kiaCnt + 1; private _grpDOA = createGroup [west, true]; [_unit] join _grpDOA; }; //Unit Info private _priWeap = primaryWeapon _unit; private _unitMagArr = magazines _unit; private _compMagArr = compatibleMagazines _priWeap; private _cntMag = 0; // Count Primary Weapon Magazines { private _compMag = _x; { private _unitMag = _x; if (_compMag == _unitMag) then {_cntMag = _cntMag + 1}; } foreach _unitMagArr; } foreach _compMagArr; private _logger = format ["<t align='center'>%1 || H: %2<br/>W: %3 || Mags: %4</t><br/><br/>", _unit, _health, _priWeap, _cntMag]; _hintStr = _hintStr + _logger; } foreach _unitArr; _logger = format ["<t align='center'>KIA: %1</t><br/>", kiaCnt]; _hintStr = _hintStr + _logger; hint parseText _hintStr; 2 Share this post Link to post Share on other sites
Ibragim A 163 Posted September 16, 2022 You also need to fix the block that counts the magazines suitable for the primary weapon. Your block counts the same magazine several times. Do it like this: // Count Primary Weapon Magazines { if (_x in _compMagArr) then {_cntMag = _cntMag + 1}; } foreach _unitMagArr; 2 Share this post Link to post Share on other sites
scottb613 285 Posted September 16, 2022 On 9/16/2022 at 5:04 PM, Ibragim A said: You also need to fix the block that counts the magazines suitable for the primary weapon. Your block counts the same magazine several times. Do it like this: // Count Primary Weapon Magazines { if (_x in _compMagArr) then {_cntMag = _cntMag + 1}; } foreach _unitMagArr; Hi Folks, Thanks so much as well. I'm a novice - so corrections and critical feedback is ALWAYS most welcome. It's how I learn. Let me go over your posts in detail. I'll see if I can figure out my mistake. I'll have to correct it elsewhere - as I've used that block before. 😉 Regards, Scott 1 Share this post Link to post Share on other sites
Larrow 2828 Posted September 17, 2022 On 9/16/2022 at 12:23 PM, scottb613 said: I've tested [hint] and it works with 20 lines of text and does support carriage returns - [format] doesn't seem to. hint format[ "%1\n%2", "first line", "second line" ]; eg _hint = ""; { _hint = format[ "%1%2\n", _hint, _x ]; }forEach ( primaryWeapon player call BIS_fnc_compatibleMagazines ); hint _hint; 3 Share this post Link to post Share on other sites
scottb613 285 Posted September 17, 2022 Hi Folks, Thanks again @Larrow - hmm - I must have bungled my test of [format] - I'll go over that again. 🙂 Regards, Scott Share this post Link to post Share on other sites
scottb613 285 Posted September 17, 2022 On 9/17/2022 at 7:01 PM, Harzach said: *edit* - back pocket post 🙃 Hi Folks, Hah - now that’s hardcore ArmA… 🙂 Regards, Scott Share this post Link to post Share on other sites
scottb613 285 Posted September 22, 2022 Hi Folks, I've updated my script based on the help I've gotten here. It's working pretty well from my perspective. Two more questions come to mind. Question: Is there a way to get the unit number assigned to a unit in the HUD (1,2,3,4 for F1, F2, F3, F4 respectively)? Question: I split the "weapon" variable via [splitString] as most of the info I didn't feel was needed in the display. For SOG - I just needed field 1 as their weapon syntax made it pretty easy. The issue is that [splitString] introduced a trailing quote on my status display and I don't know how to remove it. It's not impacting the output very much - just irksome. Updated Script Reveal hidden contents // SCOsquadStatus.sqf private _unitArr = units player; private _hintStr = ""; private _unitCnt = 1; private _unitCntStr = ""; private _healthStr = ""; { //Unit Info private _unit = _x; private _health = round ((1 - damage _unit) * 100); private _weapPri = primaryWeapon _unit; private _weapPriStr = (str _weapPri splitstring "_") select 1; private _magUnit = magazines _unit; private _magCompArr = compatibleMagazines _weapPri; private _magCnt = 0; private _magCntStr = ""; // Count Primary Weapon Magazines { if (_x in _magCompArr) then {_magCnt = _magCnt + 1}; } foreach _magUnit; // Pad Zero Mag if (_magCnt < 10) then { _magCntStr = format ["0%1", _magCnt]; } else { _magCntStr = _magCnt; }; // Pad Zero Unit if (_unitCnt < 10) then { _unitCntStr = format ["0%1", _unitCnt]; } else { _unitCntStr = _unitCnt; }; // Format Output - Pad Zero Health if (_health == 100) then { _healthStr = format ["%1", _health]; private _logger = format ["<t align='center'>%1 || Fit:%2 || Mag:%4 || Wep:%3</t><br/>", _unitCntStr, _healthStr, _weapPriStr, _magCntStr]; _hintStr = _hintStr + _logger; }; if ((_health < 100) and (_health >= 10)) then { _healthStr = format ["0%1", _health]; private _logger = format ["<t align='center'>%1 || Fit:%2 || Mag:%4 || Wep:%3</t><br/>", _unitCntStr, _healthStr, _weapPriStr, _magCntStr]; _hintStr = _hintStr + _logger; }; if (_health < 10) then { _healthStr = format ["00%1", _health]; private _logger = format ["<t align='center'>%1 || Fit:%2 || Mag:%4 || Wep:%3</t><br/>", _unitCntStr, _healthStr, _weapPriStr, _magCntStr]; _hintStr = _hintStr + _logger; }; //Increment Unit _unitCnt = _unitCnt + 1; } foreach _unitArr; // Display Status hint parseText _hintStr; sleep 10; hint parseText _hintStr; Thanks... Regards, Scott Share this post Link to post Share on other sites
Ibragim A 163 Posted September 22, 2022 On 9/22/2022 at 1:33 PM, scottb613 said: Question: Is there a way to get the unit number assigned to a unit in the HUD (1,2,3,4 for F1, F2, F3, F4 respectively)? Try by this way: getUnitPositionId = { private ["_vvn", "_str"]; _vvn = vehicleVarName _this; _this setVehicleVarName ""; _str = str _this; _this setVehicleVarName _vvn; parseNumber (_str select [(_str find ":") + 1]) }; _id = _unit call getUnitPositionId; 1 Share this post Link to post Share on other sites
scottb613 285 Posted September 22, 2022 Hi Folks, Thanks - I'll give that a shot. I've found that when using "heal and revive" scripts the unit numbers and team assignments are lost on occasion - needing me to reevaluate the number assignments periodically. On 9/22/2022 at 4:45 PM, Ibragim A said: Try by this way: getUnitPositionId = { private ["_vvn", "_str"]; _vvn = vehicleVarName _this; _this setVehicleVarName ""; _str = str _this; _this setVehicleVarName _vvn; parseNumber (_str select [(_str find ":") + 1]) }; _id = _unit call getUnitPositionId; Regards, Scott Share this post Link to post Share on other sites
Larrow 2828 Posted September 22, 2022 Reveal hidden contents // SCOsquadStatus.sqf private _hint = ""; _fnc_stringPadding = { params[ [ "_string", "", [ "", 0 ] ], [ "_numDigits", 0, [ 0 ] ] ]; if ( _string isEqualType 0 ) then { _string = str _string; }; private _padding = "000"; _padding = _padding select[ 0, _numDigits - count _string ]; format[ "%1%2", _padding, _string ]; }; _fnc_getUnitFormationPosition = { params[ "_unit" ]; private _vvn = vehicleVarName _unit; _unit setVehicleVarName ""; private _str = str _unit; _unit setVehicleVarName _vvn; _str select[ (_str find ":") + 1 ] }; { //Unit Info _x params[ "_unit" ]; //Get weapon display name private _priWeapon = primaryWeapon _unit; private _priWeapDisplayName = getText( configFile >> "CfgWeapons" >> _priWeapon >> "displayName" ); //Get unit health private _health = round ((1 - damage _unit) * 100); _health = [ _health, 3 ] call _fnc_stringPadding; //Count Primary Weapon Magazines private _compMags = compatibleMagazines _priWeapon; private _magCnt = { _x in _compMags }count magazines _unit; _magCnt = [ _magCnt, 2 ] call _fnc_stringPadding; //Get unit formation position _unitFormPos = [ _unit ] call _fnc_getUnitFormationPosition; _unitFormPos = [ _unitFormPos, 2 ] call _fnc_stringPadding; // Format Output _hint = format[ "%1<t align='center'>%2 || Fit: %3 || Mag: %4 || Wep: %5</t><br/>", _hint, _unitFormPos, _health, _magCnt, _priWeapDisplayName ]; }forEach units player; // Display Status hint parseText _hint; 2 Share this post Link to post Share on other sites
scottb613 285 Posted September 22, 2022 On 9/22/2022 at 7:10 PM, Larrow said: Reveal hidden contents // SCOsquadStatus.sqf private _hint = ""; _fnc_stringPadding = { params[ [ "_string", "", [ "", 0 ] ], [ "_numDigits", 0, [ 0 ] ] ]; if ( _string isEqualType 0 ) then { _string = str _string; }; private _padding = "000"; _padding select[ 0, _numDigits - count _string ]; }; _fnc_getUnitPositionId = { params[ "_unit" ]; private _vvn = vehicleVarName _unit; _unit setVehicleVarName ""; private _str = str _unit; _unit setVehicleVarName _vvn; _str select[ (_str find ":") + 1 ] }; { //Unit Info _x params[ "_unit" ]; //Get weapon display name private _priWeapon = primaryWeapon _unit; private _priWeapDisplayName = getText( configFile >> "CfgWeapons" >> _priWeapon >> "displayName" ); //Get unit health private _health = round ((1 - damage _unit) * 100); _health = format[ "%1%2", [ _health, 3 ] call _fnc_stringPadding, _health ]; //Count Primary Weapon Magazines private _compMags = compatibleMagazines _priWeapon; private _magCnt = { _x in _compMags }count magazines _unit; _magCnt = format[ "%1%2", [ _magCnt, 2 ] call _fnc_stringPadding, _magCnt ]; //Get unit formation position _unitFormPos = [ _unit ] call _fnc_getUnitPositionId; _unitFormPos = format[ "%1%2", [ _unitFormPos, 2 ] call _fnc_stringPadding, _unitFormPos ]; // Format Output _hint = format[ "%1<t align='center'>%2 || Fit: %3 || Mag: %4 || Wep: %5</t><br/>", _hint, _unitFormPos, _health, _magCnt, _priWeapDisplayName ]; }forEach units player; // Display Status hint parseText _hint; Hi Folks, Thank you again as well. Hah - I know I'm not much of a coder and my solutions aren't very elegant. Seeing better ways of coding is very helpful and appreciated. Let me play with this as well and see if I can grasp all of what you're doing. 🙂 Regards, Scott Share this post Link to post Share on other sites
Larrow 2828 Posted September 22, 2022 Changed the previous post, Moved the string padding format into the function. Might make it a little more readable. 1 Share this post Link to post Share on other sites
scottb613 285 Posted September 22, 2022 Hi Folks, Works like a champ - I had to make one small edit though and remove my tag line from the header - as that would be pure plagiarism on my part - LOL. 😉 I did split the weapon string (different source) and that worked without the annoying extra quote - odd. Nicely done - sir. I'll try to put it to good use and use your fine example in my other projects. Thank you and everyone that helped me here. Regards, Scott 1 Share this post Link to post Share on other sites