Code: Select all
-- Returns the average percentage damage of a given set of units.  Intended to be used for calculating the attrition of larger ground forces.
 
 unitOfInterest = {
 -- guids go here
 }
 
 function averageAttrition(units, mySide)
     totalDpPercent = 0
     avgDpPercent = 0        
     for u, unt in ipairs(units) do
         if(ScenEdit_GetUnit( { side=mySide, guid=unt } )  ~= nil) then
             unit = ScenEdit_GetUnit( { side=mySide, guid=unt } )        
             print(unit.name.." Damaged: "..unit["damage"].dp_percent)
             totalDpPercent = totalDpPercent + unit["damage"].dp_percent
         else
             totalDpPercent = totalDpPercent + 100
         end        
     end
     avDpPercent = totalDpPercent / (#units)
     return avDpPercent
 end
 
 print(averageAttrition(unitOfInterest, "RED")) 
					 
					