morrtz

MissionStatisticsHandler

Apr 29th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.70 KB | None | 0 0
  1. local eStatHandler = {}
  2.  
  3. ESHCoalition =
  4. {
  5.     [1] = "red",
  6.     [2] = "blue",
  7. }
  8.  
  9. ESHUCategory =
  10. {
  11.     [1] = "GROUND_UNIT",
  12.     [2] = "AIRPLANE",
  13.     [3] = "HELICOPTER",
  14.     [4] = "SHIP",
  15.     [5] = "STRUCTURE",
  16. }
  17.  
  18. ESHGCategory =
  19. {
  20.     [1] = "AIRPLANE",
  21.     [2] = "HELICOPTER",
  22.     [3] = "GROUND",
  23.     [4] = "SHIP",
  24. }
  25.  
  26. ESHOfield =
  27. {
  28.     [1] = "time",
  29.     [2] = "coalition",
  30.     [3] = "type",
  31.     [4] = "player",
  32.     [5] = "playerTarget",
  33.     [6] = "typeTarget",
  34.     [7] = "weaponCategory",
  35.     [8] = "weaponFlag",
  36. }
  37.  
  38. StatTable =
  39. {
  40.     [1] =
  41.     {
  42.         [1] = {},
  43.         [2] = {},
  44.         [3] = {},
  45.         [4] = {},
  46.     },
  47.     [2] =
  48.     {
  49.         [1] = {},
  50.         [2] = {},
  51.         [3] = {},
  52.         [4] = {},
  53.     },
  54. }
  55.  
  56.  
  57. function SecondsToClock(sSeconds)
  58. local nSeconds = sSeconds
  59.     if nSeconds == 0 then
  60.         --return nil;
  61.         return "00:00:00";
  62.     else
  63.         nHours = string.format("%02.f", math.floor(nSeconds/3600));
  64.         nMins = string.format("%02.f", math.floor(nSeconds/60 - (nHours*60)));
  65.         nSecs = string.format("%02.f", math.floor(nSeconds - nHours*3600 - nMins *60));
  66.         return nHours..":"..nMins..":"..nSecs
  67.     end
  68. end
  69.  
  70. function eStatHandler:onEvent(e)
  71. if e.initiator then
  72.     local eid = e.initiator.id_
  73.     local uGroup = e.initiator:getGroup()
  74.     local uCoa = uGroup:getCoalition()
  75.     local gCategory = uGroup:getCategory() + 1
  76.     local uType = e.initiator:getTypeName()
  77.     local uName = e.initiator:getName()
  78.     --if e.initiator:getPlayerName() == nil then
  79.         local uPlayer = "AI"
  80.     --else
  81.         --local uPlayer = e.initiator:getPlayerName()
  82.     --end
  83.     if e.id == world.event.S_EVENT_HIT then
  84.         local etid = e.target.id_
  85.         local eTarget = e.target
  86.         local eTargetType = eTarget:getTypeName()
  87.         local uTargetGroup = eTarget:getGroup()
  88.         local uTargetCoa = uTargetGroup:getCoalition()
  89.         local gTargetCategory = uTargetGroup:getCategory() + 1
  90.         local wDesc = e.weapon:getDesc()
  91.         local wCategory = e.weapon.Category[wDesc[category]]
  92.         local wFlag = e.weapon.flag
  93.         --if eTarget:getPlayerName() == nil then
  94.             local eTargetPlayer = "AI"
  95.         --else
  96.             --local eTargetPlayer = eTarget:getPlayerName()
  97.         --end
  98.         if StatTable[uTargetCoa][gTargetCategory][etid] == nil then
  99.             StatTable[uTargetCoa][gTargetCategory][etid] = {}
  100.             table.remove(StatTable[uTargetCoa][gTargetCategory][etid],5)
  101.             table.remove(StatTable[uTargetCoa][gTargetCategory][etid],6)
  102.             table.remove(StatTable[uTargetCoa][gTargetCategory][etid],7)
  103.             table.remove(StatTable[uTargetCoa][gTargetCategory][etid],8)
  104.             table.insert(StatTable[uTargetCoa][gTargetCategory][etid],5,eTargetPlayer)
  105.             table.insert(StatTable[uTargetCoa][gTargetCategory][etid],6,eTargetType)
  106.             table.insert(StatTable[uTargetCoa][gTargetCategory][etid],7,wCategory)
  107.             table.insert(StatTable[uTargetCoa][gTargetCategory][etid],8,wFlag)
  108.         end
  109.     elseif e.id == world.event.S_EVENT_DEAD
  110.     or e.id == world.event.S_EVENT_EJECTION
  111.     or e.id == world.event.S_EVENT_PILOT_DEAD
  112.     or e.id == world.event.S_EVENT_CRASH then
  113.         if StatTable[uCoa][gCategory][eid] == nil then
  114.             StatTable[uCoa][gCategory][eid] = {}
  115.             table.insert(StatTable[uCoa][gCategory][eid],1,SecondsToClock(timer.getTime()))
  116.             table.insert(StatTable[uCoa][gCategory][eid],2,ESHCoalition[uCoa])
  117.             table.insert(StatTable[uCoa][gCategory][eid],3,uType)
  118.             table.insert(StatTable[uCoa][gCategory][eid],4,uPlayer)
  119.             table.insert(StatTable[uCoa][gCategory][eid],9,"end")
  120.         elseif not StatTable[uCoa][gCategory][eid][9] == "end" then
  121.             table.insert(StatTable[uCoa][gCategory][eid],1,SecondsToClock(timer.getTime()))
  122.             table.insert(StatTable[uCoa][gCategory][eid],2,ESHCoalition[uCoa])
  123.             table.insert(StatTable[uCoa][gCategory][eid],3,uType)
  124.             table.insert(StatTable[uCoa][gCategory][eid],4,uPlayer)
  125.             table.insert(StatTable[uCoa][gCategory][eid],9,"end")
  126.         end
  127.     end
  128. end
  129. end
  130.  
  131. world.addEventHandler(eStatHandler)
Advertisement
Add Comment
Please, Sign In to add comment