{"name":"nearTargets","operator":null,"title":"nearTargets","type":"command","url":"https://community.bistudio.com/wiki/nearTargets","revid":377595,"updated":"2026-01-02T07:00:21Z","groups":["Object Detection"],"status":"ok","replaced_by":[],"games":[{"game":"arma1","name":"Armed Assault","version":"1.07"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma1","name":"Armed Assault","version":"1.07"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Returns a list of targets within the defined range. \"Targets\" are not restricted to enemy units.","syntaxes":[{"syntax":"unit nearTargets range","since":null,"effect":null,"exec":null,"params":[{"name":"unit","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"unit: Object"},{"name":"range","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"range: Number"}],"returns":{"type":"Array of Arrays in format [position, type, side, subjectiveCost, object, positionAccuracy]:","types":["Array"],"description":"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- 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","operator":null,"left":{"text":"unit","types":["Object"]},"right":{"text":"range","types":["Number"]}}],"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*/"]}],"multiplayer":null,"problems":null,"aliases":[],"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- 0\t\t\tclass CAManBase : Man\n- 1.6\t\tclass SoldierWB : CAManBase\n- 2\t\t\tclass USMC_Soldier_Base : SoldierWB\n- 3.9\t\tclass 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- 0\t\tclass All\n- class AllVehicles : All\n  - 0.0005\t\tclass Land : AllVehicles\n  - 0.02\t\tclass LandVehicle : Land\n  - 0.12\t\tclass Tank : LandVehicle\n  - 0.25\t\tclass 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."}],"categories":["ArmA: Armed Assault: New Scripting Commands","ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Object Detection","Introduced with Armed Assault version 1.07","Scripting Commands","Take On Helicopters: Scripting Commands"]}