Blinking SAM Search Radars

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
SeaQueen
Posts: 1432
Joined: Sat Apr 14, 2007 4:20 am
Location: Washington D.C.

Blinking SAM Search Radars

Post by SeaQueen »

Hi Guys! I wrote some code for causing SAMS to "blink" their search radars randomly according to fixed intervals (e.g. 15 of the last 45 minutes).

First I created a "Scenario Start" event with a "Scenario Load" trigger, and a LUA action called, "Set Scenario Variables"

Code: Select all

 -- these variables control the fraction of the time a SAM site will emit
 
 ScenEdit_SetKeyValue('TimeToEmit', '15')    -- minutes
 ScenEdit_SetKeyValue('TotalTimeInterval', '30')  -- minutes
 
 -- e.g. "15 of the last 30 minutes"
 
Next I created another LUA action to be fired at the scenario start called "Initialize SAM Emitting Times" This creates two tables which will be used later; samSiteList and timeEmitting. It then initializes the "timeEmitting" table with random values keyed to the guids stored in samSiteList.

Code: Select all

 -- contains the guid of each SAM site
 
 samSiteList = {'4346229a-6bdd-4328-9e96-9243be190055',  '11de0af6-3989-4e80-bdbc-ff4b1015c6b7',  '2fd972c5-fa9c-47eb-ba92-5302bb4487eb'}  -- list of all SAM sites in the scenario which will "blink" their search radars
 
 -- each SAM site will start in a different state of having emitted for 'm' minutes, this table will store that state
 timeEmitting = {}
 
 --gets  total time interval  
 local t_max = tonumber(ScenEdit_GetKeyValue('TotalTimeInterval'))
 
 for i, s in ipairs(samSiteList) do   
       timeEmitting[s]=  math.random(0, t_max)   -- randomizes the starting state of each SAM site
 end 
 
 
Finally, I created an "Every Minute" trigger with another LUA action. That event determines which SAM sites need to be active and passive. The code which goes in the action is:

Code: Select all

 local emit_max = tonumber(ScenEdit_GetKeyValue('TimeToEmit'))   --- gets maximum emission time from the scenario variables
 local t_max = tonumber(ScenEdit_GetKeyValue('TotalTimeInterval'))  -- gets maximum total time interval from the scenario variables
 
 
 -- loops over the sites on the samSiteList (see Initialize SAM Emitting Times action)
 -- determines if a SAM site has emitted for more than it's allocated emission time
 -- if it has then it turns the site off
 -- checks to see if the total interval has bee exceeded
 -- if it has, it resets the interval to zero
 
 for i, s in ipairs(samSiteList) do
     timeEmitting[s] = timeEmitting[s] + 1
     if ( timeEmitting[s] >=  emit_max) then
            ScenEdit_SetEMCON('Unit', s, 'Radar=Passive')
     else 
            ScenEdit_SetEMCON('Unit', s, 'Radar=Active')
     end
 
    if( timeEmitting[s]  >= t_max) then
            timeEmitting[s] = 0
    end 
 end
 

User avatar
tjhkkr
Posts: 2430
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Blinking SAM Search Radars

Post by tjhkkr »

Thank you for this script!
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
ddural
Posts: 21
Joined: Thu Apr 07, 2011 12:22 pm

RE: Blinking SAM Search Radars

Post by ddural »

I just ran this script through LUA. I didn't get any errors. When I hit start the radars do not come on.

ScenEdit_SetKeyValue('TimeToEmit', '1') -- minutes
ScenEdit_SetKeyValue('TotalTimeInterval', '2') -- minutes

samSiteList = {'4939521c-9fe9-46ce-9699-36e6de0664e9', 'ca804685-1715-4f6f-8852-e808a10fcc53', 'bcd1f243-0256-49ab-aa70-b85d4c459219'} -- list of all SAM sites in the scenario which will "blink" their search radars

-- each SAM site will start in a different state of having emitted for 'm' minutes, this table will store that state
timeEmitting = {}

--gets total time interval
local t_max = tonumber(ScenEdit_GetKeyValue('TotalTimeInterval'))

for i, s in ipairs(samSiteList) do
timeEmitting[s]= math.random(0, t_max) -- randomizes the starting state of each SAM site
end
local emit_max = tonumber(ScenEdit_GetKeyValue('TimeToEmit')) --- gets maximum emission time from the scenario variables
local t_max = tonumber(ScenEdit_GetKeyValue('TotalTimeInterval')) -- gets maximum total time interval from the scenario variables


-- loops over the sites on the samSiteList (see Initialize SAM Emitting Times action)
-- determines if a SAM site has emitted for more than it's allocated emission time
-- if it has then it turns the site off
-- checks to see if the total interval has bee exceeded
-- if it has, it resets the interval to zero

for i, s in ipairs(samSiteList) do
timeEmitting[s] = timeEmitting[s] + 1
if ( timeEmitting[s] >= emit_max) then
ScenEdit_SetEMCON('Unit', s, 'Radar=Passive')
else
ScenEdit_SetEMCON('Unit', s, 'Radar=Active')
end

if( timeEmitting[s] >= t_max) then
timeEmitting[s] = 0
end
end

ironhand125
User avatar
SeaQueen
Posts: 1432
Joined: Sat Apr 14, 2007 4:20 am
Location: Washington D.C.

RE: Blinking SAM Search Radars

Post by SeaQueen »

How did you set it up? Was there an initialization action at scenario start and an "every minute" action?

Did you add the guids of the SAMs you want to blink to the samSiteList array?
sarjen
Posts: 114
Joined: Wed Jul 14, 2004 5:10 pm
Contact:

RE: Blinking SAM Search Radars

Post by sarjen »

I tried it too and it worked for me.
Post Reply

Return to “Lua Legion”