{"name":"nearTargets","title":"nearTargets","type":"command","url":"https://community.bistudio.com/wiki/nearTargets","revid":377595,"updated":"2026-01-02T07:00:21Z","groups":["Object Detection"],"status":"ok","games":{"arma1":"1.07","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma1 1.07","arma3_since":"0.50","description":"Returns a list of targets within the defined range. \"Targets\" are not restricted to enemy units.","syntaxes":[{"syntax":"unit nearTargets range","params":[{"name":"unit","type":"Object","type_expr":"Object"},{"name":"range","type":"Number","type_expr":"Number"}],"returns":{"type":"Array of Arrays","type_expr":"Array<Array>","description":"in format [position, type, side, subjectiveCost, object, positionAccuracy]:\n- position: Position3D - perceived position including judgment and memory errors - type: String - perceived, gives only what was recognized - side: Side - perceived side - subjectiveCost: Number - positive for enemies, more positive for more important or more dangerous enemies - object: Object object type, can be used to get more information if needed - positionAccuracy: Number - assumed accuracy of the perceived position","text":"Array of Arrays in format [position, type, side, subjectiveCost, object, positionAccuracy]:\n\n- position: Position3D - perceived position including judgment and memory errors\n- type: String - perceived, gives only what was recognized\n- side: Side - perceived side\n- subjectiveCost: Number - positive for enemies, more positive for more important or more dangerous enemies\n- object: Object object type, can be used to get more information if needed\n- positionAccuracy: Number - assumed accuracy of the perceived position"},"form":"binary","left":{"text":"unit"},"right":{"text":"range"}}],"examples":[{"text":"```sqf\nplayer nearTargets 100;\n// can return e.g\n/*\n    [\n        [[2555.33,2535.33,1.32708],\"SoldierEB\",EAST,214222,EAST 1-1-A:1],\n        [[2550.39,2482.5,1.32696],\"SoldierWB\",WEST,0,WEST 1-1-A:2]\n    ]\n*/\n```","code":["player nearTargets 100;\n// can return e.g\n/*\n\t[\n\t\t[[2555.33,2535.33,1.32708],\"SoldierEB\",EAST,214222,EAST 1-1-A:1],\n\t\t[[2550.39,2482.5,1.32696],\"SoldierWB\",WEST,0,WEST 1-1-A:2]\n\t]\n*/"]}],"see_also":["targets","targetsQuery","targetsAggregate","targetKnowledge","knowsAbout","reveal","forgetTarget","setTargetAge","getHideFrom","findNearestEnemy","nearestBuilding","nearestObject","nearestObjects","nearObjects","nearestLocation","nearEntities","nearSupplies","nearestLocationWithDubbing","nearObjectsReady","nearRoads","nearestMines"],"notes":[{"user":"mrcurry","date":"2011-02-17T16:00:00Z","text":"A subjective cost greater than 0 does not necessarily mean the target is an enemy unit. **Any** unit, that have yet to be identified by the unit, have a small positive cost in the range 0 to 1."},{"user":".kju","date":"2012-01-15T17:45:00Z","text":"The quality/detail level of the info depends on the knowsAbout value of the sourceUnit about the targetUnit:\n\n- For infantry:\n  - ] 0 , 1.5 [ - side unknown, some position offset, identified as SoldierWB\n  - [ 1.5, 1.6 [ - side identified, subjective cost set\n  - [ 1.6, 2 [ - type identified better (USMC_Soldier_Base)\n  - [ 2 , 3.6 [ - type identified precisely (USMC_Soldier)\n  - [ 3.6, 4 ] - position identified precisely\n\nThe values seems closely linked to the accuracy value of the given targetUnit class and its parents up in the config tree:\n\n- 0 class CAManBase : Man\n- 1.6 class SoldierWB : CAManBase\n- 2 class USMC_Soldier_Base : SoldierWB\n- 3.9 class USMC_Soldier : USMC_Soldier_Base\n\n- For tanks:\n  - ] 0 , 0.03 [ - side unknown, some position offset, identified as LandVehicle\n  - [ 0.03, 0.13 [ - type identified better (Tank)\n  - [ 0.13, 0.3 [ - type identified better (M1A1)\n  - [ 0.3 , 1.5 [ - side identified, subjective cost set\n  - [ 1.5 , 3.6 [ - side identified precisely (CIV), subjective cost adjusted\n  - [ 3.6 , 4 ] - position identified precisely\n\nThe values seems closely linked to the accuracy value of the given targetUnit class and its parents up in the config tree:\n\n- 0 class All\n- class AllVehicles : All\n  - 0.0005 class Land : AllVehicles\n  - 0.02 class LandVehicle : Land\n  - 0.12 class Tank : LandVehicle\n  - 0.25 class M1A1 : Tank"},{"user":".kju","date":"2012-01-17T16:14:00Z","text":"- When an unit dies, it is nearTargets array gets emptied after some seconds.\n- When an unit dies, its reference will get removed from other units nearTargets' arrays immediately.\n- A target will be removed from the array after about 360 seconds without contact."},{"user":".kju","date":"2012-01-21T20:00:00Z","text":"Position accuracy seems to be a radius in meters from the perceived position."}]}