tmoilanen
Posts: 72
Joined: 10/19/2011 Status: offline
|
Hi - below is a LUA script that I use to blink radars on and off. You will need to add all of the units that you want to exhibit this behavior to the "myunitname" table. I try and use uniform unit names (eg '651 RTB') to make it easier to loop through all of the desired units. This example gives each unit a 50% chance (myemcon = math.random(1,2)) to activate radars (or leave radar active if it is already on.) You can adjust the myemcon variable as needed to decrease the probability. To enable this in a scenario, I typically will create an Event with a regular time trigger of 15 minutes and then have the LUA script as the action. Hope this helps. myside = 'VKS'
myunitname = {651,652,653,654,151,152,153,154,155,156,491,492,251,252,253,254,255,256,981,982,983,984,985,986,987,988}
-- table with unit numbers - use uniform naming for your radar units, eg '651 RTB'
for i = 1,#myunitname -- this is a loop through all of the units in the myunitname table
do
unitname = myunitname[i] ..'RTB' --unit to be checked/activated
myunit = ScenEdit_GetUnit({side=myside,name=unitname})
print(myunit)
print(myunit.obeyEMCON)
myunit.obeyEMCON = true --set obey EMCON value
print(myunit.obeyEMCON)
myemcon = math.random(1,2) --get myemcon variable (1,2) is 50% chance that radar is activated
if myemcon == 1 then
ScenEdit_SetEMCON('Unit',unitname,'Inherit=false;Radar=Active') --activate radar if condition is true (myemcom = 1)
else
ScenEdit_SetEMCON('Unit',unitname,'Inherit=false;Radar=Passive') --deactivate radar if condition is false (myemcon <> 1)
print(myunit.sensors)
end
end
|