Jump to content

Smarter Sam


Prof_hilactic

Recommended Posts

This is my first try at a script and it is a bit of a Frankenstein (bits of script taken left right and center) so if you recognise part of the script as being yours, it is normal and thank you.

 

The aim was to have the sam radar to shut off for a random time and for the unit to disperse randomly if a SEAD missile is targeting it .

 

 

SEAD_launch = {}

function SEAD_launch:onEvent(event)

 

if event.id == world.event.S_EVENT_SHOT then -- detecte un depart missile/bomb/cannon

local _grp = Unit.getGroup(event.initiator)-- identifie le groupe qui a tire

local _groupname = _grp:getName() -- retourne le nom du groupe

local _unittable = {event.initiator:getName()} -- retourne le nom des unites dans le groupe

local _SEADmissile = event.weapon -- identifie l'arme utilise

local _SEADmissileName = _SEADmissile:getTypeName() -- retourne le type d'arme

trigger.action.outText( string.format("Alerte, depart missile " ..string.format(_SEADmissileName)), 20)

-- debut de la deuxieme boucle

if _SEADmissileName == "KH-58" or _SEADmissileName == "KH-25MPU" then -- Si l arme utilise est un KH-58 ou Kh-25MPU

 

local _targetMim = Weapon.getTarget(_SEADmissile)

local _targetMimname = Unit.getName(_targetMim)

local _targetMimgroup = Unit.getGroup(Weapon.getTarget(_SEADmissile))

local _targetMimcont= _targetMimgroup:getController()

mist.groupRandomDistSelf(_targetMimgroup,300,'Rank',250,20)

Controller.setOption(_targetMimcont, AI.Option.Ground.id.ALARM_STATE,AI.Option.Ground.val.ALARM_STATE.GREEN)

local SuppressedGroups = {}

local function SuppressionEnd(id)

id.ctrl:setOption(AI.Option.Ground.id.ALARM_STATE,AI.Option.Ground.val.ALARM_STATE.RED)

SuppressedGroups[id.groupName] = nil

end

local id = {

groupName = _targetMimgroup,

ctrl = _targetMimcont

}

local delay = math.random(5, 15)

if SuppressedGroups[id.groupName] == nil then

SuppressedGroups[id.groupName] = {

SuppressionEndTime = timer.getTime() + delay,

SuppressionEndN = SuppressionEndCounter --Store instance of SuppressionEnd() scheduled function

}

 

 

timer.scheduleFunction(SuppressionEnd, id, SuppressedGroups[id.groupName].SuppressionEndTime) --Schedule the SuppressionEnd() function

end

end

end

 

end

 

world.addEventHandler(SEAD_launch)

 

 

 

 

It works, however it moves the full group and I would like only one unit (the radar) to move. How do I do it or is it impossible? (having a group of one unit is not an option the SA-6 needs a radar and a missile launcher in the same group)

 

P.S the code is a right mess any help on cleaning it would be greatly appreciated, so I can learn.

P.P.S there is some odd behiavour with the KH-58. Against a sborka the missile self destroy as soon as the radar shut off. Against a SA-6 STR it flies ok and will even re-aquire the target if the radar is turned back on. I might need to find a way to delay the restart of the radar until the KH-58 is dead.

  • Like 1
Link to comment
Share on other sites

Nice! I'm bookmarking this thread to try it out in my missions once I get around to it. Why don't it look for western ARMs like the AGM-88 HARM?

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Link to comment
Share on other sites

I haven't messed around with MIST or mission scripting yet, but just taking a stab in the dark

 

The MIST function groupRandomDistSelf() calls mist.getLeadPos() to get the position of the leader of the group

 

mist.getLeadPos = function(group)
if type(group) == 'string' then -- group name
	group = Group.getByName(group)
end

local units = group:getUnits()

local leader = units[1]
if not leader then  -- SHOULD be good, but if there is a bug, this code future-proofs it then.
	local lowestInd = math.huge 
	for ind, unit in pairs(units) do
		if ind < lowestInd then
			lowestInd = ind
			leader = unit
		end
	end
end
if leader and Unit.isExist(leader) then  -- maybe a little too paranoid now...
	return leader:getPosition().p
end
end

 

Assuming that your radar unit is not the leader of the group....

 

Maybe you can refactor that method to not get the leader of the group, instead get the radar unit and move only the radar unit..

 

This all depends on whether the engine allows units to move individually of the leader.

314-я смешанная авиационная дивизия

314th Mixed Aviation Division: The "Fighting Lemmings"- Forums: http://314thsquadron.enjin.com/ - ED Forum Group: http://forums.eagle.ru/group.php?groupid=119

Link to comment
Share on other sites

As far as I know only aircraft can be given new orders to individual units. Ships and ground vehicles are assigned orders across the whole group.

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

  • 3 weeks later...
  • 3 months later...

I have a problem with this script:

 

1ymsup.jpg

 

I try reloading the mission with only this script & w/o it, only happens with smarter sams script...

 

The sams doesn't seem to be more smarter than usual, dont turn off their radars & dont move on launch (KH-25MPU)

 

DCS version 1.2.7.23803

Mist v3.3

 

can anyone help? thanks!

Link to comment
Share on other sites

There seems to be an extra space that has slipped into the script, line 19:

 

Controller.setOption(_targetMimcont, AI.Option.Ground.id.ALARM_STATE,AI.Option.Ground.v al.ALARM_STATE.GREEN)

 

should be

 

Controller.setOption(_targetMimcont, AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.GREEN)

 

I hope it will work this way ;)

 

For some reason, a space seems to slip in when using the spoilers tag :doh:

 

Just in case, the whole script, corrected:

 

SEAD_launch = {} 
function SEAD_launch:onEvent(event)

if event.id == world.event.S_EVENT_SHOT then -- detecte un depart missile/bomb/cannon
local _grp = Unit.getGroup(event.initiator)-- identifie le groupe qui a tire 
local _groupname = _grp:getName() -- retourne le nom du groupe
local _unittable = {event.initiator:getName()} -- retourne le nom des unites dans le groupe
local _SEADmissile = event.weapon -- identifie l'arme utilise 
local _SEADmissileName = _SEADmissile:getTypeName() -- retourne le type d'arme
trigger.action.outText( string.format("Alerte, depart missile " ..string.format(_SEADmissileName)), 20)
-- debut de la deuxieme boucle
if _SEADmissileName == "KH-58" or _SEADmissileName == "KH-25MPU" then -- Si l arme utilise est un KH-58 ou Kh-25MPU

local _targetMim = Weapon.getTarget(_SEADmissile)
local _targetMimname = Unit.getName(_targetMim)
local _targetMimgroup = Unit.getGroup(Weapon.getTarget(_SEADmissile))
local _targetMimcont= _targetMimgroup:getController()
mist.groupRandomDistSelf(_targetMimgroup,300,'Rank ',250,20)
Controller.setOption(_targetMimcont, AI.Option.Ground.id.ALARM_STATE,AI.Option.Ground.val.ALARM_STATE.GREEN)
local SuppressedGroups = {}
local function SuppressionEnd(id)
id.ctrl:setOption(AI.Option.Ground.id.ALARM_STATE, AI.Option.Ground.val.ALARM_STATE.RED)
SuppressedGroups[id.groupName] = nil
end
local id = {
groupName = _targetMimgroup,
ctrl = _targetMimcont
}
local delay = math.random(5, 15)
if SuppressedGroups[id.groupName] == nil then
SuppressedGroups[id.groupName] = {
SuppressionEndTime = timer.getTime() + delay,
SuppressionEndN = SuppressionEndCounter --Store instance of SuppressionEnd() scheduled function
}


timer.scheduleFunction(SuppressionEnd, id, SuppressedGroups[id.groupName].SuppressionEndTime) --Schedule the SuppressionEnd() function
end
end
end

end

world.addEventHandler(SEAD_launch)

Link to comment
Share on other sites

It works now, thank you!

 

But... I find this too effective, one test mission fly (IA vs IA) shots 9x KH-25MPU, and only 1 get the target.. maybe 0, because it hit a launcher not a radar.. and all other missiles explodes nearly launch :/

 

It's possible to retard some time from lauch the reaction from the SAMs? and make it less accurate?

 

Another time, thanks ;)

Link to comment
Share on other sites

  • 6 months later...

Now that life is a bit less busy, I am able to spend more time on DCS :pilotfly:

 

Here is an update on the script, it works with mist 3.5 and DCS 1.2.10.

 

I have added the AGM-88 and the probability of a SAM evading the missile is skill based :

 

An Average SAM will have 10% chance

Good 50%

High 70%

Excellent 90%

 

To prevent any copy paste error I have included the Lua and one exemple.

 

I still haven't made any progress in learning Lua so any help making the script more tidy is welcome.

 

Have fun

SAM_smart_final.miz

sam_smart_finale.lua

Link to comment
Share on other sites

  • 5 months later...

SCRIPT EFFECTIVENESS

 

Thanks for this lua file.

 

I have been experimenting with it...I have no lua skills, but after testing with Russian SAM systems....I note that the behavior of turning off Radar and movement when being attacked by AGM88s...only occurs with:

 

SA-8,SA-10,SA-11.

 

Not sure at all why I don't get indications of RADAR on, /off condtions with the others I tested.

 

In addition to the above I tested.

 

SA-3,SA-6,SA-13, SA-19.

 

SA-15 successfully defends against AGMs of all types, but no radar turn off or movement noticed.

 

Again, thanks for your script.

Velocity MicroI7-4790 Windows 7 Home Premium 16Gigs RAM EVGA NVIDIA GTX 1070 500GB SSD TM Hotas Warthog

Link to comment
Share on other sites

  • 9 months later...
  • 3 months later...

Very small, easy to understand and well-working script (and very needed!) Everything works (DCS 1.5).

Another 2 missiles should be added: "KH-31P" and "ALARM". I made it myself. You can also change a bit the behaviour of SAMs by yourself.

Link to comment
Share on other sites

Thanks for this lua file.

 

I have been experimenting with it...I have no lua skills, but after testing with Russian SAM systems....I note that the behavior of turning off Radar and movement when being attacked by AGM88s...only occurs with:

 

SA-8,SA-10,SA-11.

 

Not sure at all why I don't get indications of RADAR on, /off condtions with the others I tested.

 

In addition to the above I tested.

 

SA-3,SA-6,SA-13, SA-19.

 

SA-15 successfully defends against AGMs of all types, but no radar turn off or movement noticed.

 

Again, thanks for your script.

 

DCS 1.5. After ARM launch (I tested only with Russian ARMs launched from Su-34s and Su-24s):

 

- SA-6 tracking radar shuts off and moves;

- SA-8 shuts off and moves;

- SA-15 shuts off and moves;

- SA-19 shuts off and moves;

- SA-11 tracking radar attempts to shut off and move but is too slow;

- SA-11 launchers shut off radars when working autonomously;

- SA-13 is a non-radar system;

- SA-3 tracking radar is not mobile (in this game) and does not turn off (at least visually). Same with tracking radars of SA-10, Hawk, Patriot (unfortunately).

 

So script works almost 100% as intended (or at least as it can, as game engine allows).


Edited by Havoc86
Link to comment
Share on other sites

  • 1 year later...
  • 5 months later...
  • 5 months later...
  • 4 years later...

Работающая версия на 20.06.2022 - sam_smart_finale2022_by_Prof_hilactic.lua

Работающая и измененная версия на 20.06.2022 - sam_smart_finale2022_by_Prof_hilacticMOD.lua

Изменено срабатывание скрипта. 

Уровень SAM "наилучший" - SAM выключает излучение и меняет свое местоположение.

Уровень SAM "высокий" - SAM только выключает излучение и остается на месте. Желательно для стационарных SAM  и медленно разворачивающихся, таких как БУК.

Уровень SAM "хороший" и "средний" - скрипт не работает.

Новый mist - mist_4_4_90.lua  Но работает и со старым mist.

Демонстрационная миссия sam_smart_finale2022_by_Prof_hilactic - sam_smart_finale2022_by_Prof_hilactic.miz

Демонстрационная миссия sam_smart_finale2022_by_Prof_hilacticMOD - sam_smart_finale2022_by_Prof_hilacticMOD.miz

Демонстрационное видео - 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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