local function diceRollPerUnit(tbl,sType,unit,percentActive) local r = math.random(1,100) print('diceRollPerUnit rolled: ' .. tostring(r)) if r < percentActive then ScenEdit_SetEMCON(sType, tbl[unit], 'Radar=Active') print('Unit set Active: ' .. tostring(tbl[unit])) else ScenEdit_SetEMCON(sType, tbl[unit], 'Radar=Passive') print('Unit set Passive: ' .. tostring(tbl[unit])) end end local function SetRandomEMCOMAll(t,sType) if((t ~=nil and #t > 1) and sType ~= nil) then --make sure table isn't nil and has 2 entries or more. for i = 1,(#t),1 do diceRollPerUnit(t,sType,i,40) end elseif(t ~=nil and #t == 1) then -- only single entry diceRollPerUnit(t,sType,1,40) else print('Invalid parameters, nil, or table with less than two entries.'); end print('\r') end local function SetRandomEMCOM(t,sType) if((t ~=nil and #t > 1) and sType ~= nil) then --make sure table isn't nil and has 2 entries or more. local randomUnit = math.random(1,#t) --random selection between 1 and table row count. print('randomUnit= ' .. tostring(randomUnit) .. ' - ' .. tostring(t[randomUnit])) diceRollPerUnit(t,sType,randomUnit,40) elseif(t ~=nil and #t == 1) then -- only single entry diceRollPerUnit(t,sType,1,40) else print('Invalid parameters, nil, or table with less than two entries.'); end print('\r') end local WorkUnit = {'UnitS400', 'UnitS4002', 'UnitS4003', 'UnitS4004'} SetRandomEMCOM(WorkUnit,'Unit') SetRandomEMCOMAll(WorkUnit,'Unit')