DCS func knowTarget - ED Forums
 


Notices

Reply
 
Thread Tools Display Modes
Old 01-17-2020, 11:01 PM   #1
CougarFFW04
Member
 
Join Date: Jul 2018
Posts: 240
Default DCS func knowTarget

Hi everyone

I am looking forward to assign a given target to wingmen and my only idea at the moment is to use the DCS func knowTarget:
function Controller.knowTarget(Class self, Object object , boolean type, boolean distance)
that is supposed to do the following : Forces the controller to become aware of the specified target, without the controller manually detecting the object itself. Applies only to a Unit Controller. Cannot be used at the group level

I use the following code

Code:
leadGroup = ATME.C_Group.getByName("A10") -- get the group controller
leader = leadGroup:getUnitByName("Pilot1") -- get pilot1 controler
target = ATME.C_StaticObject.getByName("Reserv1")  -- get target controller
leader.knowTarget(target)
I have no errrors to get the controllers of the plane "Pilot1" and target but an error on the knowTarget. I suppose I do not use it correctly...

Any idea about I am doing wrong ?

Thanks

Last edited by CougarFFW04; 01-18-2020 at 12:17 AM.
CougarFFW04 is offline   Reply With Quote
Old 01-19-2020, 04:52 AM   #2
Grimes
ED Testers Team
 
Grimes's Avatar
 
Join Date: Jan 2006
Location: Black Mesa
Posts: 8,178
Default

I don't use ATME, so I don't know what the leader and target represent in terms of scripting engine objects. Which is likely where your issues occurred at.

The following code works. Though it must be stated the AI won't really attack static objects automatically with CAS tasking. Well they can, but it depends on the type of object. I set it to a building and the AI didn't react, but I switched it to a static object of a tank and the AI attacked. It all has to do with the attributes of the object they are allowed to attack.

Code:
local con = Unit.getByName('p'):getController()
local obj = StaticObject.getByName('s1')
con:knowTarget(obj)
__________________
The right man in the wrong place makes all the difference in the world.
Current Projects: Scripting Wiki, Something...
Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD for DCS 1.5/2.0, IADScript, Mission Editing Wiki!, Mission Building Forum
Grimes is offline   Reply With Quote
Old 01-19-2020, 05:47 AM   #3
CougarFFW04
Member
 
Join Date: Jul 2018
Posts: 240
Default

Hi Grimes,

Will try asap and come back to you.

Thanks
CougarFFW04 is offline   Reply With Quote
Old 01-19-2020, 03:37 PM   #4
CougarFFW04
Member
 
Join Date: Jul 2018
Posts: 240
Default

Hi Grimes,

Tried but can't get this working properly...
But actually I would like to know what is

- object ? Is that the name ? the type ? whatever. it is not clear what the scripting engine is looking for... For the map object I tried with providing Name (ty also with TypeName) that DOES exist as I get them directly in game but it complains. So what is object exactly ?
Is seems that this command does NOT have any impact on the choice of the target.

And this is not documented:

- what is the boolean type ? Although it is optional it might play a role...

- what is distance ? Although it is optional it might play a role as well...

So actually concerning what I would like to do I have two problems :

- The first one is that I am not sure if this command will make the designated object as the target for the controller.

- The second one is that I have an error if I provide what seems to be "name" of a scenery object...

Any idea ?

Thanks

Last edited by CougarFFW04; 01-19-2020 at 04:49 PM.
CougarFFW04 is offline   Reply With Quote
Old 01-19-2020, 07:15 PM   #5
Hardcard
Member
 
Hardcard's Avatar
 
Join Date: May 2013
Posts: 745
Default

Quote:
Originally Posted by CougarFFW04 View Post

- object ? Is that the name ? the type ?
The DCS object, which you need to provide as first parameter for :knowTarget().

Use standard DCS code instead of ATME:

Code:
leadGroup = Group.getByName("A10") -- get the group
leader = leadGroup:getUnit(1) -- get pilot1 unit object
leader_Controller = leader:getController() -- get pilot1 unit controller
target = StaticObject.getByName("Reserv1")  -- get target object
leader_Controller:knowTarget(target,true,true)

Quote:
Originally Posted by CougarFFW04 View Post
- what is the boolean type ? Although it is optional it might play a role...

- what is distance ? Although it is optional it might play a role as well...
Both parameters are booleans (they can be set to either true or false)

Boolean type = If set to true, target type is known
Boolean distance = If set to true, distance to target is known


Quote:
Originally Posted by CougarFFW04 View Post
So actually concerning what I would like to do I have two problems :

- The first one is that I am not sure if this command will make the designated object as the target for the controller.
Probably won't, but it doesn't hurt to try.

Quote:
Originally Posted by CougarFFW04 View Post
- The second one is that I have an error if I provide what seems to be "name" of a scenery object...

You mean this line?
Code:
target = ATME.C_StaticObject.getByName("Reserv1")
If it gives you an error, either the name is incorrect, syntax is incorrect, the object is not a static / it's not reachable.

Try with standard DCS code, if you still get an error, name is incorrect or object isn't reachable:
Code:
StaticObject.getByName("Reserv1")
__________________

Last edited by Hardcard; 01-19-2020 at 07:17 PM.
Hardcard is offline   Reply With Quote
Old 01-19-2020, 08:12 PM   #6
CougarFFW04
Member
 
Join Date: Jul 2018
Posts: 240
Default

Hi Hardcard

Thanks for comments.


I know it is a bit confusing as I am testing different things...

But in this case I am NOT speaking abour StaticObject but about SceneryObject
So it sounds that it is not reacheable...
Too bad for the "attack ground object" offered...



I got the name of the scenery Object in game with the DCS command

world.searchObjects(Object.Category.SCENERY, searchVol, ifFound)

So Im a sure it is a valid name but when I provide this name it complains...

Last edited by CougarFFW04; 01-19-2020 at 08:17 PM.
CougarFFW04 is offline   Reply With Quote
Old 01-19-2020, 11:57 PM   #7
CougarFFW04
Member
 
Join Date: Jul 2018
Posts: 240
Default

Quote:
Originally Posted by Hardcard View Post
Probably won't, but it doesn't hurt to try.
Seems it doesn't...
So useless.
CougarFFW04 is offline   Reply With Quote
Old 01-20-2020, 01:07 AM   #8
Habu_69
Member
 
Join Date: Jul 2011
Location: USA VA
Posts: 952
Default

But just think of the great learning experience you have had!
Habu_69 is offline   Reply With Quote
Old 01-20-2020, 04:30 AM   #9
Grimes
ED Testers Team
 
Grimes's Avatar
 
Join Date: Jan 2006
Location: Black Mesa
Posts: 8,178
Default

AI don't really think about scenery objects at all. Mostly because scenery objects are coalition-less. Best you can do is a line of sight check or if some AI unit is near by use that object and whether or not the AI is aware of it to determine if the scenery object would be detected.
__________________
The right man in the wrong place makes all the difference in the world.
Current Projects: Scripting Wiki, Something...
Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD for DCS 1.5/2.0, IADScript, Mission Editing Wiki!, Mission Building Forum
Grimes is offline   Reply With Quote
Old 01-20-2020, 09:43 AM   #10
Hardcard
Member
 
Hardcard's Avatar
 
Join Date: May 2013
Posts: 745
Default

Quote:
Originally Posted by CougarFFW04 View Post

But in this case I am NOT speaking abour StaticObject but about SceneryObject
That's the problem, statics and scenery objects belong to different classes... also, scenery objects only have a handful of methods available.

You can still use AttackMapObject task with scenery objects, the tricky part is to find them and filter them out by type name.


Here, this script will order individual AI planes to attack scenery radar found at the closest enemy airbase (just need to provide the unit names of the chosen planes. Also, they must be set to Ground Attack or CAS):

Code:
local Striker_Name_SET = { "Name of the first unit in ME", "Name of the second unit in ME" , } -- etc.
  
local function Get_Closest_Enemy_Airbase(Unit_Object)
                   
               
               if Unit_Object:getCoalition() == coalition.side.BLUE then
                      
                  Airbase_Coalition = coalition.side.RED
                     
               elseif Unit_Object:getCoalition() == coalition.side.RED then
                      
                  Airbase_Coalition = coalition.side.BLUE    
               end
               
               Distance_Table = {}    
                   
               for i, Airbase_Obj in ipairs( coalition.getAirbases(Airbase_Coalition) ) do   
                   
                   if Airbase_Obj then 
                      
                      local Airbase_Object = Airbase_Obj
                      local Airbase_Coord = Airbase_Object:getPoint()
                      local Unit_Coord = Unit_Object:getPoint()
                      
                      local Distance2D = math.floor( ( ( Airbase_Coord.x - Unit_Coord.x ) ^ 2 + ( Airbase_Coord.z - Unit_Coord.z ) ^ 2 ) ^ 0.5, 0 )
                      
                      table.insert(Distance_Table, Distance2D)
                   end
               end
               
               local Threshold = 1000000000
               local Closest_Index = 0

               for k = 1 , #Distance_Table do
                   
                   local asNum = Distance_Table[k]
  
                   if ( asNum and asNum < Threshold ) then
                       Threshold = asNum
                       Closest_Index = k
                   end
               end
               
               local Closest_Object = coalition.getAirbases(Airbase_Coalition)[Closest_Index]
               local Closest_Name = Closest_Object:getName()
               local Closest_Distance = Distance_Table[Closest_Index]
               local Closest_Point = Closest_Object:getPoint()
              
   return Closest_Object , Closest_Point
end                   


local function Search_Destroy_EWR(Striker)
   
   local Closest_Airbase_Object , Closest_Airbase_Coord = Get_Closest_Enemy_Airbase(Striker) 
   
   local Search_Area = {id = world.VolumeType.SPHERE, params = {point = Closest_Airbase_Coord , radius = 2000}} -- Radius must be at least 500 meters (~1600 feet) for the volume search to work!!!
         
       local function Evaluate_Zone(Scenery_Object)
                 
            if Scenery_Object then 
               
               if Scenery_Object:getCategory() == Object.Category.SCENERY and Scenery_Object:getName() and Scenery_Object:getTypeName() and Scenery_Object:getPoint() then
                  
                  local Scenery_Type = Scenery_Object:getTypeName()
                 
                  if Scenery_Type == "RLS-37" then -- RLS-37 is a radar scenery object found at Caucasus airbases
                     
                     Radar_Coord = Scenery_Object:getPoint()
                     
                     Radar_Vec2 = { x = Radar_Coord.x , y = Radar_Coord.z }
                    
                  end
               end
            end
        end
        
    world.searchObjects(Object.Category.SCENERY, Search_Area, Evaluate_Zone)
    
    if Radar_Vec2 then
       
       local Strike_EWR_Task = { id = 'AttackMapObject', params = { point = Radar_Vec2, groupAttack = false, expend = "ALL" } }
    
       local Striker_Controller = Striker:getController()
       
       Striker_Controller:pushTask(Strike_EWR_Task)
  
    elseif Radar_Vec2 == nil then
       
       trigger.action.outText("No RLS-37 found on "..Closest_Airbase_Object:getName().." airbase (closest)", 10)
    end
end
  
  
  for i, Striker_Name in pairs( Striker_Name_SET ) do
      
      if Unit.getByName(Striker_Name) and Unit.getByName(Striker_Name):isExist() then
     
         Search_Destroy_EWR(Unit.getByName(Striker_Name))
      end
  end
__________________

Last edited by Hardcard; 01-20-2020 at 10:18 AM.
Hardcard is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 04:54 PM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.