thy_ 164 Posted February 6, 2022 Need you 🙂 I'm building a debug hint and I'd like to see in that hint message the name of the current playableUnits selected by AI. Edited: AI = only one suicide bomber who runs to the nearest player in multiplayer coop with 2 or more players. hint format ["Nearest player = %1.", _playerNearest]; // <---------------- Not working. While {true} do { //code { //code _playerNearest = _x; } forEach playableUnits; //code }; I dont know the syntax to the hint return the selected playableUnit name. Share this post Link to post Share on other sites
Harzach 2517 Posted February 7, 2022 _playerNearest doesn't yet exist when you call the hint. It does exist once the forEach loop starts, but then it can change with every cycle. My first thought would be to create an array containing the distances to each playableUnits then using selectMin to find the nearest: while {true} do { _array = []; { _dist = _pos distance _x; // _pos is the thing you are measuring distance from _array pushback _dist; } forEach playableUnits; _min = selectMin _array; _index = _array find _min; _playerNearest = playableUnits select _index; hint format ["Nearest player = %1.", _playerNearest]; sleep 1; }; I'm not sure if playableUnits is a "consistent" array, though - I.E. if the order of its elements is stable. It seems to be from testing the above, but just in case you could copy it to a new array each cycle: while {true} do { _playableArray = playableUnits; _array = []; { _dist = _pos distance _x; _array pushback _dist; } forEach _playableArray; _min = selectMin _array; _index = _array find _min; _playerNearest = _playableArray select _index; hint format ["Nearest player = %1.", _playerNearest]; sleep 1; }; This is a bunch of late-night hackery, so as always, there is probably a more elegant solution. Also, your snippet above seems to be an abstraction, so I have no idea what's supposed to be happening. 1 Share this post Link to post Share on other sites
pierremgi 4905 Posted February 7, 2022 Not sure what you mean by: the current playableUnits selected by AI Nearest player from a position: hintNearestPlayer = TRUE; private _nearest = objNull; private _plyrsDist = []; waitUntil {sleep 1; allPlayers isNotEqualTo []}; While {hintNearestPlayer} do { private _pos = .......... a position or an object ! ; _plyrsDist = (allPlayers select {alive _x}) apply {[_x distancesqr _pos,_x]}; // alive check not mandatory _plyrsDist sort TRUE; _nearest = _plyrsDist #0#1; hintSilent format ["Nearest player = %1.", _nearest]; sleep 1; }; Rmq: hintNearestPlayer set to false will definitely stop the hint. So not mandatory. If you want to test distance from all other players: hintNearestPlayer = TRUE; private _nearest = objNull; private _plyrsDist = []; waitUntil {sleep 1; allPlayers isNotEqualTo []}; While {hintNearestPlayer} do { private _pos = player; _plyrsDist = (allPlayers select {alive _x && !local _x}) apply {[_x distancesqr _pos,_x]}; _plyrsDist sort TRUE; _nearest = _plyrsDist #0#1; hintSilent format ["Nearest player = %1.", _nearest]; sleep 1; }; Distance from the player (locally) to nearest playable units, non-played (so AI) hintNearestPlayer = TRUE; private _nearest = objNull; private _plyrsDist = []; waitUntil {sleep 1; allPlayers isNotEqualTo []}; While {hintNearestPlayer} do { private _pos = player; _plyrsDist = (playableUnits select {alive _x && !isPlayer _x}) apply {[_x distancesqr _pos,_x]}; _plyrsDist sort TRUE; _nearest = _plyrsDist #0#1; hintSilent format ["Nearest player = %1.", _nearest]; sleep 1; }; 2 1 Share this post Link to post Share on other sites
thy_ 164 Posted February 7, 2022 7 hours ago, Harzach said: Also, your snippet above seems to be an abstraction, so I have no idea what's supposed to be happening. 4 hours ago, pierremgi said: Not sure what you mean by: the current playableUnits selected by AI AI = only one suicide bomber who runs to the nearest player in multiplayer coop with 2 or more players. I'm reading your ideas and thinking about'em. I come back in a few hours. Share this post Link to post Share on other sites
Tankbuster 1747 Posted February 7, 2022 allPlayers and BIS_fnc_nearestposition Share this post Link to post Share on other sites
thy_ 164 Posted February 7, 2022 I love your ideas, dudes. Here's what I've done. if (_debugVbiedMonitor == true) then // if debug on, so... { // show info on screen: hint format ["CODE CODE CODE \n\nNearest target = %4.\n\n CODE CODE CODE", code, code, code, _targetNearest]; }; //CODE if (_suicidalTargets != 3) then // if the suicidal focus is NOT just one special target, so... { _threatPos = getPosATL _vbied; // takes the current vbied position. if (_suicidalTargets == 2) then // if the suicidal consider only enemy players as potential targets. { // pick up the dist from each enemy alive to vbied and load the array with the distances: _targetDistance = (allPlayers select {alive _x}) apply {[_x distanceSqr _threatPos, _x]}; }; if (_suicidalTargets == 1) then // if the suicidal consider enemy players and playable units as potential targets. { // Warning: if your mission has AI disable and _suicidalTargets is = 1, you'll face an error. _targetDistance = (playableUnits select {alive _x}) apply {[_x distanceSqr _threatPos,_x]}; }; if (_suicidalTargets == 0) then // if the suicidal consider all enemy units (player, playable unit, regular unit) as potential targets. { // PERFORMANCE KILLER WHEN TOO MUCH TARGETS _targetDistance = ((units _suicidalEnemy) select {alive _x}) apply {[_x distanceSqr _threatPos,_x]}; }; _targetDistance sort true; // sort the distances in array from smallest to biggest. _targetNearest = _targetDistance #0#1; // the closest target (player, for example) is in the _targetDistance array first position. } else // if the suicidal focus finally is just one special target, do... { _targetNearest = _specialTarget; // the nearest target is the only one: _specialTarget. sleep 2; // execution breathe. }; //CODE Cheers. 1 Share this post Link to post Share on other sites