Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Blinking SAM Search Radars

View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Air / Naval Operations >> Mods and Scenarios >> Lua Legion >> Blinking SAM Search Radars Page: [1]
Message << Older Topic   Newer Topic >>
Blinking SAM Search Radars - 7/5/2018 9:28:40 PM   

Posts: 811
Joined: 4/14/2007
From: Washington D.C.
Status: offline
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"

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

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

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:

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')
           ScenEdit_SetEMCON('Unit', s, 'Radar=Active')

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

< Message edited by SeaQueen -- 7/5/2018 9:49:02 PM >
Post #: 1
RE: Blinking SAM Search Radars - 7/24/2018 1:56:25 PM   

Posts: 2279
Joined: 6/3/2010
Status: offline
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.

(in reply to SeaQueen)
Post #: 2
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Air / Naval Operations >> Mods and Scenarios >> Lua Legion >> Blinking SAM Search Radars Page: [1]
Jump to:

New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts

Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI