-- special aciton to repair selected units -- restricts itself to only select units that are airfacilities. local counter = 0; local function isAirFacility(u) if u.type == 'Facility' then if (#u.components > 0) then for k,v in ipairs(u.components) do if v.comp_type == 'AirFacility' then return true; end end end end return false; end local function RepairUnit(u) local startdmg = tonumber(u.damage.startdp) local currentdmg = tonumber(u.damage.dp) for k,v in pairs(u.components) do if v.comp_type == 'AirFacility' then ScenEdit_SetUnitDamage({guid=u.guid, components={{v.comp_guid,'none'}} }); end end if currentdmg < startdmg then ScenEdit_SetUnitDamage({guid=u.guid, fires=0, flood=0, dp=((startdmg - currentdmg) * -1)}); else ScenEdit_SetUnitDamage({guid=u.guid, fires=0, flood=0, dp=0}); end counter = counter + 1; end local function processUnits() print('starting!') local sUnits=ScenEdit_SelectedUnits() if(sUnits.units ~=nil) then local u; for k,v in pairs(sUnits.units) do --loop though selected unit table u = ScenEdit_GetUnit({guid=v.guid}); --get the unit. if((u ~=nil) and tonumber(u.damage.dp) < tonumber(u.damage.startdp)) then --skip units that are not damaged. print('Player is triggering a repair on facility ' .. u.name); if isAirFacility(u) then RepairUnit(u); end end end u = nil; ScenEdit_MsgBox(string.format('Completed repaires on %s units',tostring(counter)), 1); else ScenEdit_MsgBox('Please select one or more units first.', 1); end end processUnits();