DCS func isTargetDetected

From DCS World Wiki - Hoggitworld.com

Scripting Root

Envrioment: Mission Scripting
Function: isTargetDetected Added with: 1.2.6
Member Of: Controller
Syntax: multiple Controller.isTargetDetected(Class self , Object Target , enum detectionType1, enum detectionType2, enum detectionType3 ...)
Description: Returns multiple entries that define a number of values if the target is detected by the Unit or group associated with the controller.

Values returned are:

 boolean detected, -- boolean value if the target is detected
 boolean visible, -- boolean value if target is visible by line of sight
 ModelTime lastTime, -- the last model time that the target was detected
 boolean type, -- if the type of target is known
 boolean distance, -- if distance to the target is known
 Vec3 lastPos, -- last known position of the target
 Vec3 lastVel -- last know velocity vector of the target

Function is available at the unit level for all unit types.

When used with a Group Controller the function will return expected values only with Ground and Ship groups.


Return Value: multiple
Return Example:
Examples: The following returns al of the entries:

local detected , visible , lastTime , type , distance , lastPos , lastVel = uCon:isTargetDetected(target)

To output a list of how the aircraft is detecting the target as a message:

  local con = Unit.getController(Unit.getByName('whatever'))
  local target = Unit.getByName('target')
  local m = {}
  for det, enum in pairs(Controller.Detection) do
     m[#m+1] = det .. " : "
     m[#m+1] = tostring(con:isTargetDetected(target, enum))
     m[#m+1] = "\n"
  end
  trigger.action.outText(table.concat(m), 20, true)
Related Functions: Controller: setTask, resetTask, pushTask, popTask, hasTask, setCommand, setOption, setOnOff, setAltitude, setSpeed, knowTarget, isTargetDetected, getDetectedTargets
Notes: Detection Types
Conroller.Detection  
  VISUAL  1
  OPTIC   2
  RADAR   4
  IRST    8
  RWR     16
  DLINK   32