Jump to content

NEW smart SAM net script. Need to be imprvoved


ESAc_matador

Recommended Posts

Hello guys...

 

I finnally got finnished the first module of this script!!! My intentions were to try to improve or at least, give us flyers other options with the integrated Air Defense System. Since the fantastic IADS script from Grimes does not work, i wanted to still make scenarios were the SAMs were something else than just points to not pass across. Mainly, those small SAMs type, Tor, Roland, and so.

 

THe script is very basic, as my lua programming skills are, but with some tweaking you can make the most of it.

 

What does it does?:

It makes the SAM systems dependant on one or more EWR radar systems.

 

How?:

The SAMs are switched off initially, and they wait till the EWR "report" there is an aircraft in his area. So when you are in the kill zone AND detected by the EWR the SAM is when it switch on.

Once the SAM is On, you can hide from the EWR but since the SAM is On, it will remain on untill every aircraft in the zone is out.

If you are not detected by the EWR but there is another aircraft (your wingman) flying higher, that is detected, it activates the SAM... so, you are in danger now!!!

 

Pro:

Flying Low avoiding the EWR signature keeps you cover,

Flying fast, avoid the SAM to be armed or if they do, you are close to the leaving area sooner, so it is less dangerous.

 

Cons: AAA, and Manpands welcome you to come down!!

 

Future:

I would like to make the SAM more unpredictable, with espontaneous activations to see by their own... somethink like.

Random Switch On, if there is unit in the area, then keep ON until no ones there. Also, I would like them to move espontaneously, or everytime it Switch Off, change position let say, 300, 500 meters.

 

CONFIGURATION:

 

The script for the moment is only for redside Sams against blue planes.

 

You can configure the units in the net, you have a table of EWR and another for SAMs dont forget that the name and the group must be the same as the script. It is because sometimes I use unitname an other groupname. I havent tested with more units in the group.

 

Radius, you have two radius, the first is the activation zone, and the second is the deactivation zone.

 

There is no limit, just take into account that filling missions with too many scripts and units can make lag.

 

I havent tested in multiplayer, so I hope you help me to improve it!!!

 

here is the code.

 

function findTargets()

local samsites = {'sam1','sam2','sam3'}
local ewrsites = {'ewr1','ewr2'}
  for k,v in pairs(ewrsites) do
           ewr = ewrsites[k]

   local unit = Unit.getByName(ewr)
   if unit ~= nil then
       local unitController = unit:getGroup():getController() --be careful, I'm not sure if the bug where client groups are not accessable will stuff this up if a player is in the vehicle at the time
       local detectedTargets = unitController:getDetectedTargets(Controller.Detection.RADAR)
       -- Controller.Detection.RADAR is the type of detection (radar in this case)
       -- leave it blank for all types (it includes RWR if the unit has one ie AWACS)
       -- for a list of detection types see here: http://wiki.hoggit.us/view/DCS_func_getDetectedTargets
       
       for k,v in pairs (detectedTargets) do
           if v["object"]:getCategory() == Object.Category.UNIT then --ensure the detected object is a unit, ive had it detect weapons
               local category = getGroupCategory(v["object"]) -- pull category using workaround
               if category == "plane" or category == "helicopter" then --check category as returned by MIST
                   trigger.action.setUserFlag('400',1) --check category as returned by MIST
                   detectedblue = v["object"]:getName() --set flag
                   --replace flag number as you see fit, and value can be true / false or have a numeric value
                              
       
       for k,v in pairs(samsites) do
           sam = samsites[k]
           
       mist.flagFunc.units_in_moving_zones{
           units = {detectedblue},
           zone_units = {sam},
           flag = 500,
           radius = 10000,
           stopflag = 9999,
           req_num = 1,
           zone_type = 'cylinder',
           interval = 1,
           toggle = true
           }
       
       
       local blueplanes = mist.makeUnitTable({'[blue][plane]','[blue][helicopter]',})
        mist.flagFunc.units_in_moving_zones{
           units = blueplanes,
           zone_units = {sam},
           flag = 510,
           radius = 10000,
           stopflag = 9999,
           req_num = 1,
           zone_type = 'cylinder',
           interval = 1,
           toggle = true
           }
       
       
       if  trigger.misc.getUserFlag('400') == 1  and -- if planes or helos are detected
           trigger.misc.getUserFlag('500') == 1     -- and are inside a moving SAM zone
       then
           _group = Group.getByName(sam)
           _controller = _group:getController()
           _controller:setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.AUTO)-- we change the status to ON
           --trigger.action.outText(detectedblue  .. " detected by "  ..  sam .. ewr, 5)
          
       end
       if  trigger.misc.getUserFlag('400') == 0  and -- if planes or helos are detected
           trigger.misc.getUserFlag('500') == 1     -- and are inside a moving SAM zone
       then
           _group = Group.getByName(sam)
           _controller = _group:getController()
           _controller:setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.GREEN)-- we change the status to ON
           --trigger.action.outText(detectedblue  .. " not detected by "  ..  sam .. ewr, 5)
          
       end
       if
           trigger.misc.getUserFlag('510')== 0 
       then
           _group = Group.getByName(sam)
           _controller = _group:getController()
           _controller:setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.GREEN )-- we switch off the SAM

           --trigger.action.outText(detectedblue  .. " not detected by "  ..  sam .. ewr, 5) -- just a message
       end
       end
       end
       end
       end
       end
       
       
   end
   timer.scheduleFunction(findTargets, {}, timer.getTime() + 3)-- scan the function every 10 seconds
end


function getGroupCategory(unit) -- THIS FUNCTION TO GET AROUND CLIENT GROUPS NOT ACCESSABLE IF USING IN A MULTIPLAYER ENVIRONMENT
   local unitDB = mist.DBs.unitsById[tonumber(unit:getID())]
    if unitDB ~= nil and unitDB.category then
       return unitDB.category
   end

   return nil
end

findTargets ()

SAMNET6.lua

testscriptsam.miz


Edited by ESAc_matador
Link to comment
Share on other sites

I will give a trty tommorow mate

My Hardware: ROG Strix X570-F Gaming - AMD 5600X @ 4.7 ghz - G.SKILL TRIDENT 32GB DDR4 3200 (14-14-14-34 CL) - GigaByte 3080ti OC 12gb - Corsair MP600 Force 1TB - 2 x EVO Nvme 500GB - Virpil Warbird Base T-50CM2 and TM Throttle + Trackhat + G25 + AOC AG271QG 27"

My Modules: JF-17, F-16C, AV-8N/A, F-18C, ASJ37, MiG-15Bis, MiG-21Bis, Fw-190D, Bf-109K, P-51D, F-86F, Ka-50 III, UH-1H, Mi-8MTV2, NS430, FC3, A-10C, Mirage 2000C, L-39, F-5E-3, SA342, Spitfire, AH-64, Mirage F-1CE.

My Maps: Nevada, Normandy, Persian Gulf, Syria, South Atlantic.

Link to comment
Share on other sites

I will give a trty tommorow mate

 

 

I am really close!!!

 

but still does not work fully, because when there are two planes, it makes the loop twice, which is ok, but, if one is not in the zone... it is swithing the radar on, and off continuously, I dont know....

 

this is what I have got that works with just one plane, but several Sams

 

function findTargets()
   local unit = Unit.getByName('ewr') -- You can define a table of unit names if you want, and run them thru a loop to check each one
   if unit ~= nil then
       local unitController = unit:getGroup():getController() --be careful, I'm not sure if the bug where client groups are not accessable will stuff this up if a player is in the vehicle at the time
       local detectedTargets = unitController:getDetectedTargets(Controller.Detection.RADAR)
       -- Controller.Detection.RADAR is the type of detection (radar in this case)
       -- leave it blank for all types (it includes RWR if the unit has one ie AWACS)
       -- for a list of detection types see here: http://wiki.hoggit.us/view/DCS_func_getDetectedTargets
       
       for k,v in pairs (detectedTargets) do
           if v["object"]:getCategory() == Object.Category.UNIT then --ensure the detected object is a unit, ive had it detect weapons
               local category = getGroupCategory(v["object"]) -- pull category using workaround
               if category == "plane" or category == "helicopter" then --check category as returned by MIST
                   trigger.action.setUserFlag('400',1) --check category as returned by MIST
                   detectedblue = v["object"]:getName() --set flag
                   --replace flag number as you see fit, and value can be true / false or have a numeric value
               
               
           
       
   
       local samsites = {'sam1','sam2'}
       
       for k,v in pairs(samsites) do
           sam = samsites[k]
           
       mist.flagFunc.units_in_moving_zones{
           units = {detectedblue},
           zone_units = {sam},
           flag = 500,
           radius = 10000,
           stopflag = 9999,
           req_num = 1,
           zone_type = 'cylinder',
           interval = 4,
           toggle = true
           }
       
       if  trigger.misc.getUserFlag('400') == 1  and -- if planes or helos are detected
           trigger.misc.getUserFlag('500') == 1     -- and are inside a moving SAM zone
       then
           _group = Group.getByName(sam)
           _controller = _group:getController()
           _controller:setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.AUTO)-- we change the status to ON
           trigger.action.outText(detectedblue  .. "es detectado por"  ..  sam , 30)
          
       end
       if
           trigger.misc.getUserFlag('500')== 0 -- but if the aircraft leaves the zone independently of the EWR since the EWR already informed that SAM that there is enamies.
       then
           _group = Group.getByName(sam)
           _controller = _group:getController()
           _controller:setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.GREEN )-- we switch off the SAM

           trigger.action.outText(detectedblue  .. "no es detectado por"  ..  sam, 30) -- just a message
       end
       end
       end
       end
       end
   end
   timer.scheduleFunction(findTargets, {}, timer.getTime() + 10)-- scan the function every 10 seconds
end


function getGroupCategory(unit) -- THIS FUNCTION TO GET AROUND CLIENT GROUPS NOT ACCESSABLE IF USING IN A MULTIPLAYER ENVIRONMENT
   local unitDB = mist.DBs.unitsById[tonumber(unit:getID())]
    if unitDB ~= nil and unitDB.category then
       return unitDB.category
   end

   return nil
end

findTargets ()

 

I am learning a lot of the concepts in lua, so when I get this to work, I will try to make also the SAMs, to switch on randomly... and if they dont find anything, they will switch off, and move tto another point. things like that. I am not going to get close to the IADS but... since it does not work!!


Edited by ESAc_matador
Link to comment
Share on other sites

Can anyone tell me how to make a table of units that has been detected?

 

I am not able to do it, i am trying

 

Targets=mist.makeUnitTable(detectedTargets:getByName())

but it does not seems to work.

 

I needed to put in the second condition, simce detectedblue does not work with two or more planes. If there are two aircrafts, if in the second loop if detectedblue is outside the zone, the radar is off. Even if there is another aircraft in the zone.

 

Then, it the function restart, and again the sam is on, and goes like that, on off on off... I want the sam once switched on, to be on until there is not ANY aircraft inside.

 

Any suggestion?

Link to comment
Share on other sites

  • 3 weeks later...

One question and one idea:

 

1. What differences there are between your script and Grime's IADS script?

 

2. maybe a stupid suggestion: why don't you create a table at mission start for sobstitute sam & ewr manual table? You might use the getDesc and getType function to find EWRs and SAMs and avoid manual addition. Also you can run a small table.insert function at any spawning event so that if a unit can fall into ewr & sam category it will be automatically added to your script function.

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

1 a lot of things, GRIMES's is muuuach better, but it doesnt work im 1.5!!!! This very simple.

 

2.the problem is the lethal range to activation should depend on the type off SAM, and I dont know how to reach the maximum range od fire, not detetion of the unit but is planned.

 

By the by the way... I am very advanced on the recon script, remember? I eould need your help, we can combine with autolaase, works great but, you will see... Give me few days and I ll send to you the draft I have... It is awesome, seriously.

Link to comment
Share on other sites

1 a lot of things, GRIMES's is muuuach better, but it doesnt work im 1.5!!!! This very simple.

 

uh, missed that :noexpression:.

 

2.the problem is the lethal range to activation should depend on the type off SAM, and I dont know how to reach the maximum range od fire, not detetion of the unit but is planned.

 

Uhm, probably Grimes found a different solution in IADS script, you could have a look in it. Anyway I wasn't talking about sam properties but simply about the manual sam list (local samsites = {'sam1','sam2'}) that could be replaced looking into each unit and adding those are sams.

 

By the by the way... I am very advanced on the recon script, remember? I eould need your help, we can combine with autolaase, works great but, you will see... Give me few days and I ll send to you the draft I have... It is awesome, seriously.

 

If you need help I'll try but for the moment I'only looking in detection functions limitation... so I don't think I could offer really great solutions... but I'll try :)

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

 

 

If you need help I'll try but for the moment I'only looking in detection functions limitation... so I don't think I could offer really great solutions... but I'll try :)

 

Dont worry, i finnally took the time to learn some lua!(you have just see it) and I know what I want and the function needed, i need sometimes some help calling variables and sintax. I still have problems with, when I need to put getByname, or getbyname or GetId etc...

Link to comment
Share on other sites

then I'm glad to help if and when necessary

ChromiumDis.png

Author of DSMC, mod to enable scenario persistency and save updated miz file

Stable version & site: https://dsmcfordcs.wordpress.com/

Openbeta: https://github.com/Chromium18/DSMC

 

The thing is, helicopters are different from planes. An airplane by it's nature wants to fly, and if not interfered with too strongly by unusual events or by a deliberately incompetent pilot, it will fly. A helicopter does not want to fly. It is maintained in the air by a variety of forces in opposition to each other, and if there is any disturbance in this delicate balance the helicopter stops flying; immediately and disastrously.

Link to comment
Share on other sites

  • 2 years later...
Ups! I didnt know! Thanks for the info! It did nt work thw las time in used it. However it is good for me this script because has many applications and improve my lua skills.

 

 

Any updates.

 

I would like to get script that runs without mist

Oculus CV1, Odyssey, Pimax 5k+ (i5 8400, 24gb ddr4 3000mhz, 1080Ti OC )

 

 

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

  • Recently Browsing   0 members

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