Jump to content

DCS func knowTarget (Edit pushTask)


CougarFFW04

Recommended Posts

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

 

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


Edited by CougarFFW04
Link to comment
Share on other sites

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.

 

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:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

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


Edited by CougarFFW04
Link to comment
Share on other sites

 

- 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:

 

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

 

 

- 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

 

 

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.

 

- 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?

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:

StaticObject.getByName("Reserv1")


Edited by Hardcard
Link to comment
Share on other sites

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...


Edited by CougarFFW04
Link to comment
Share on other sites

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:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

 

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):

 

local Striker_Name_SET = { "[color="Red"]Name of the first unit in ME[/color]", "[color="red"]Name of the second unit in ME[/color]" , }[color="Blue"] -- etc.[/color]
 
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}} [color="Blue"]-- Radius must be at least 500 meters (~1600 feet) for the volume search to work!!![/color]
        
      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 [color="blue"]-- RLS-37 is a radar scenery object found at Caucasus airbases[/color]
                    
                    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


Edited by Hardcard
Link to comment
Share on other sites

Hi Hardcard

 

 

Thanks

 

Not because of whole code (thanks anyway this can be usefull for someone else) but just a line...

 

 

I always thought that the push.task (or setTask) where only possible with groups BUT not with Units...

As far as I am not wrong you are aasigning the task to the differnt planes and this is the way to assign different target to different wingmen in the same group.

 

 

If true you made my day!!!

Link to comment
Share on other sites

Sure, some tasks can be pushed to individual units, but I seem to remember that some other tasks only work at group level.

 

Lucky for you, AttackMapObject task works at unit level ;)

 

Regarding the script I provided, it includes an automatic finder of closest enemy airbase + scenery object scan... I'd say it's pretty useful stuff for any mission creator :D

Link to comment
Share on other sites

Hi Harcard,

 

Tested but actually not working.

Right now I have just tested in the mission editor with a flight of 3 F15 (pilot01 to 03) armed with MK84. They are spawned at 600ft, 430knt in colonne at WPT0 which is 1.6 nm from WPT1 and 6.5nm of the target region and there is a WPT2 a little bit further with nothing special. There are also a few ground forces a little bit further of the target region just to test what's happen with them if they are in the vicinty of the ground targets.

 

There is nothing special at the target region except 3 static objets (cible 01 to 03) i put over some 3D structures just to get their positions for the script.

 

In the ME advanced section @WPT1 I just add the following script with the option "do command" and "script".

 

local pil01 = Unit.getByName('Pilot01'):getController()
local sol01 = StaticObject.getByName('cible01'):getPoint()
local Strike_Task01 = { id = 'AttackMapObject', params = { point = sol01, groupAttack = false, expend = "ALL" } }
pil01:pushTask(Strike_Task01)

local pil02 = Unit.getByName('Pilot02'):getController()
local sol02 = StaticObject.getByName('cible02'):getPoint()
local Strike_Task02 = { id = 'AttackMapObject', params = { point = sol02, groupAttack = false, expend = "ALL" } }
pil02:pushTask(Strike_Task02)

local pil03 = Unit.getByName('Pilot03'):getController()
local sol03 = StaticObject.getByName('cible03'):getPoint()
local Strike_Task03 = { id = 'AttackMapObject', params = { point = sol03, groupAttack = false, expend = "ALL" } }
pil03:pushTask(Strike_Task03)

If I run the mission like this when they arrive @WPT1 yhey just go back nowhere...

 

IF I add a task "attack ground target" @WPT1 I have to set the small triangle somewhere and in this case they behave normally as if ths srcipt wasn't there...

 

What did I do wrong ?

 

Hereafter a screenshoot of how it look like in the ME. As you can see the second script is not activated and as nothing to do with the problem

 

 

testscript-56f944c.jpg

 

 

Thanks


Edited by CougarFFW04
Link to comment
Share on other sites

ATME, Task and group's controller

 

Hi,

 

I read the thread.

 

In ATME, a getByName on a static object works with DCS StaticObject class. For scenery object, only the next version will have its specific class.

 

Be careful, when trying to find such an object in a DCS zone using world,searchObjects, only building will be returned, no bridge for example.

 

The DCS scripting function wiki definies most of tasks to be used with a group's controller. I speak about tasks, not commands. But I saw that for AttackMapObject and Bombing, no precision, so perhaps assign those tasks to a unit's controller is possible. But the wiki may be wrong .... or not updated for group's controller tasks.

Link to comment
Share on other sites

Hi Harcard,

 

Post the mission file here.

 

Here it is.

 

Since yesterday I tried different things (replacing the flag at the bombing area by soldier, tanks,...) and different option concerning engagement rules and otions to face the menace but didn't get expected result.

 

At worst they RTB immediatly, at best they engage the target when there is nothing else in the vicinity.

 

I am looking for something that would work independantly that there are anything in the vicinity...

 

Please try and let me know.

 

Thanks in adance

TestBombing.miz

Link to comment
Share on other sites

The problem with your script is that you're providing vec3 instead of vec2 coordinates (AttackMapObject task only accepts vec2 coordinates).

 

Here, this will make the strike eagles engage the soldiers:

local pil01 = Unit.getByName('Pilot01'):getController()
local sol01 = StaticObject.getByName('cible01')
local sol01_vec2 = { x = sol01:getPoint().x , y = sol01:getPoint().z } [color="Blue"]-- Conversion to Vec2 coordinate format[/color]
local Strike_Task01 = { id = 'AttackMapObject', params = { point = sol01_vec2, groupAttack = false, expend = "ALL" } }
pil01:pushTask(Strike_Task01)

local pil02 = Unit.getByName('Pilot02'):getController()
local sol02 = StaticObject.getByName('cible02')
local sol02_vec2 = { x = sol02:getPoint().x , y = sol02:getPoint().z } [color="Blue"]-- Conversion to Vec2 coordinate format[/color]
local Strike_Task02 = { id = 'AttackMapObject', params = { point = sol02_vec2, groupAttack = false, expend = "ALL" } }
pil02:pushTask(Strike_Task02)

local pil03 = Unit.getByName('Pilot03'):getController()
local sol03 = StaticObject.getByName('cible03')
local sol03_vec2 = { x = sol03:getPoint().x , y = sol03:getPoint().z } [color="Blue"]-- Conversion to Vec2 coordinate format[/color]
local Strike_Task03 = { id = 'AttackMapObject', params = { point = sol03_vec2, groupAttack = false, expend = "ALL" } }
pil03:pushTask(Strike_Task03)


Edited by Hardcard
Link to comment
Share on other sites

but is it possible to have a list of tasks which are unit's controller suitable ?

 

Other than by trial and error, I don't know.

 

 

By the way, I think for attackGroup task, which is a group's controller task, knowTarget is ok to select several unit targets.

Is that right?

 

AttackGroup and AttackUnit tasks can also be pushed to individual units. The main difference between them and AttackMapObject is that they won't work on static and scenery targets.

Link to comment
Share on other sites

AttackGroup and AttackUnit tasks can also be pushed to individual units.

 

Those are mentionned to be group's controller suitable... in the DCS wiki. So interesting.

But, how a group or the unit will react if I use pushTask on group's controller to push an AttackGroup then add a pushTask on unit's controller (unit is one of the group) ? or if I do the opposite...

 

knowTarget may be more useful for that or not ? I wil do some tests to be sure that approach is stable with several tasks pushed by different way (group or unit controllers).

 

 

The main difference between them and AttackMapObject is that they won't work on static and scenery targets.

 

Of course.

 

I think eagle dynamics works on that actually ..

 

Thanks for your information ;)


Edited by sunski34
Link to comment
Share on other sites

but is it possible to have a list of tasks which are unit's controller suitable ?

 

 

Everything that the group task can do should be the same.

https://wiki.hoggitworld.com/view/Category:Aircraft_Task

 

Though it has been a while since I extensively tested it. I certainly recall using attack unit and bombing to distribute targets among units within a group. I am unsure of how setting options might work at a unit level.

 

I wanna say that whichever was ordered last takes precedence.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Hi Grimes,

 

so if I understood what you said, the best way is to stay at group level for tasks settings and use knowTarget at a unit level ?

 

I'm saying both should work, but I don't have an answer for what is best. I don't know if using knowTarget at a unit level would effectively act as a "datalink" between group members. Generally speaking once one unit it a group detects a target, then they all detect it or are at least aware of it.

 

IMO knowTarget has nothing to do with the target designation process.

 

It can. If AI has a task to attack tanks and you use knowTarget on a tank, then the AI flight can now have a valid target. It won't prioritize it, but if there are no other tanks detected and the AI isn't actively attacking anything then yeah, the AI should go attack that tank.

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...