tortuosit 485 Posted September 24, 2016 Hi guys, I'm a bit puzzled about finding units. I want to find all enemy infantry (SIDE != myside) units within a specific radius. I think findEntities finds all units and puts them into an array. So I could have to loop and filter over it and create a new array... or is there an easier way? Thx Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted September 24, 2016 Use BIS_fnc_enemyTargets. Cheers 1 Share this post Link to post Share on other sites
Tankbuster 1733 Posted September 24, 2016 (edited) I think you mean nearEntities? _list = player nearEntities ["Man", 1000]; Will return all the Man units within a kilometre of the player. You can then use the nice new select expression to get only the enemies from that. _nearenemies = select {side _x != side player}; Although bear in mind, this will return civilians as well. ** edited to add missing space in side_x Edited September 24, 2016 by Tankbuster 1 1 Share this post Link to post Share on other sites
tortuosit 485 Posted September 24, 2016 That "select" is interesting! Didn't know about that. Yes I meant nearEntities. As for the BIS_fnc_enemyTargets: Returns "empty array if unit doesn't know about any enemy". If unit is the player - I wonder what it thinks I know. I want to definitely return it any unit. Share this post Link to post Share on other sites
Tankbuster 1733 Posted September 24, 2016 Yes, any script or function that relies on knowsAbout is not useful if you want to get enemies your unit doesn't know about. The clue is in the name. :) You could use reveal so that your unit does knowsAbout the enemies, but I don't think that's useful to you here. So use nearEntities. It's fairly cheap on the CPU unless you use really big radii or you have a LOT of units inside that radius. That condition select is a babe, isn't it? It's worth having a good look through old code to see where it can replace old code. Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted September 24, 2016 That "select" is interesting! Didn't know about that. Yes I meant nearEntities. As for the BIS_fnc_enemyTargets: Returns "empty array if unit doesn't know about any enemy". If unit is the player - I wonder what it thinks I know. I want to definitely return it any unit. You didn't mention the player part in the OP. Try something like this: _enemySides = [side player] call BIS_fnc_enemySides; _radius = 1000; _nearEnemies = allUnits select {_x distance player < _radius AND side _x in _enemySides}; Cheers Share this post Link to post Share on other sites
Devastator_cm 434 Posted November 9, 2016 Use BIS_fnc_enemyTargets. Cheers When I try to use BIS_fnc_enemyTargets I am getting undefined variable error. The call is inside a spawned script. So I spawn a script which needs to run all the time and time to time it needs to check which enemies are around. Is there a BIS bug or can I not use this function inside a spawned script? I basicaly do something like _enemies = leader _group1 call BIS_fnc_EnemyTargets; Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted November 9, 2016 Seems like leader _group1 is undefined. Try to swap it with player and see if the problem persists. Cheers Share this post Link to post Share on other sites
Devastator_cm 434 Posted November 9, 2016 actually it was defined. I hinted it to screen as far as I remember (it was late night) but will try once more. One question though, this bis function returns individual units or the groups back?I don't want to have a situation like tank sees 2 infantry from a team which has in total 10 units.If function returns the group then I will assume all are seen and then pick a random one from them to attack which might be the unlucky guy who was actually not visible at all and will be pissed of when sees that tank started to move in his direction :) Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted November 9, 2016 One question though, this bis function returns individual units or the groups back? I don't want to have a situation like tank sees 2 infantry from a team which has in total 10 units. If function returns the group then I will assume all are seen and then pick a random one from them to attack which might be the unlucky guy who was actually not visible at all and will be pissed of when sees that tank started to move in his direction :) It's explained in the link. Click it. Cheers Share this post Link to post Share on other sites
Devastator_cm 434 Posted November 9, 2016 I already checked the link after your first post above but links says" Return list of nearby enemy targets for given unit. "I don't know what is target in Arma. Is it using group as target or the unit itself as target. I will test it by myself then to figure it out Share this post Link to post Share on other sites
1212PDMCDMPPM 200 Posted November 9, 2016 Why don't you use findNearestEnemy ? https://community.bistudio.com/wiki/findNearestEnemy Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted November 9, 2016 Why don't you use findNearestEnemy ? https://community.bistudio.com/wiki/findNearestEnemy Would not return units if none are known, so not what OP wants. Cheers Share this post Link to post Share on other sites
Devastator_cm 434 Posted November 9, 2016 Why don't you use findNearestEnemy ? https://community.bistudio.com/wiki/findNearestEnemy Nearest enemy returns not all the enemies known by the unit but just the closest one. I want to get all the units (not the groups) known by unit so he can share the knowsabout with other allied units in area (as they might not aware of the enemy units yet). And when allied units get the knowsabout they will pick targets and start the attack Share this post Link to post Share on other sites
1212PDMCDMPPM 200 Posted November 9, 2016 Oops, sorry, I just forgot the OP. Share this post Link to post Share on other sites