Robustcolor 30 Posted September 14, 2020 Hi, this variable below is an array including [positions,units,players] from using apply + sort command and it refreshes with new units,positions and players from time to time. i usually select either the unit or the player by doing _playertarget = _groupDistances #0#2; But the question is, if i would like to select all the units not the players or the positions inside this array, how do i do that? since _playertarget = _groupDistances #0#2 only gives me one object, in this case the player. _groupDistances = [[136517,O Alpha 1-1:6,Player1],[174721,O Alpha 1-1:5,Player2],[195925,O Alpha 1-2:1,Player3]]; I would like to do something like { _x doMove "somehwere"; } count "the units from array"; Share this post Link to post Share on other sites
pierremgi 4736 Posted September 14, 2020 It's a little bit hard to understand what your array is made of! If I'm right: _groupDistances = [ [dist1,unit1,player1],[dist2,unit2,player2],[dist3,unit3,player3],...]; so returning: [[136517,O Alpha 1-1:6,Player1],[174721,O Alpha 1-1:5,Player2],[195925,O Alpha 1-2:1,Player3]]; ? I can't see neither position nor array of units.... The best way could be to re-formulate what you are trying to obtain. Share this post Link to post Share on other sites
Robustcolor 30 Posted September 14, 2020 @pierremgi Sorry, made the first post abit hasty. _groupDistances = []; { _unit = _x; _groupDistances append (allPlayers select {alive _x} apply {[_x distanceSqr _unit, _unit, _x]}) } count (allUnits select {side _x isEqualTo EAST); _groupDistances sort true; RESULT: _groupDistances = [[136517,O Alpha 1-1:6,Player1],[174721,O Alpha 1-1:5,Player2],[195925,O Alpha 1-2:1,Player3]]; Usually i use _playertarget = _groupDistances #0#2; Gives me in this case the first one, [Player1] Is it possible to select all those units in each [] that are not players and use them in a context of { _x dosomething } count Share this post Link to post Share on other sites
pierremgi 4736 Posted September 14, 2020 ? _groupDistances = []; { _unit = _x; if (!isPlayer _unit) then {_unit domove somewhere}; _groupDistances append (allPlayers select {alive _x} apply {[_x distanceSqr _unit, _unit, _x]}) } forEach (allUnits select {side _x isEqualTo EAST}); Or you can re-apply for nuts: { _x doMove somewhere} forEach (_groupDistances apply {_x #1} select {!isPlayer _x}); Share this post Link to post Share on other sites
Robustcolor 30 Posted September 16, 2020 Thanks @pierremgi, this is how i did now. _groupDistances = []; { _unit = _x; _groupDistances append (allPlayers select {_x distance2d _unit < 150} apply {[_x distanceSqr _unit, _unit, _x]}); _groupDistances sort true; _target = _groupDistances #0#2; _unit doMove _target; } forEach (allUnits select {side _x isEqualTo EAST}); Question, will the code _unit doTarget _target; only execute on those units <150 or closer or will it still execute it on allUnits side EAST in this forEach? Share this post Link to post Share on other sites
pierremgi 4736 Posted September 16, 2020 _unit(s) are allUnits from EAST side. That's what you wrote. So yes, the code is on any EAST unit. _target is the nearest player of all players located within 150 m of one _unit (EAST) Share this post Link to post Share on other sites