Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local eStatHandler = {}
- ESHCoalition =
- {
- [1] = "red",
- [2] = "blue",
- }
- ESHUCategory =
- {
- [1] = "GROUND_UNIT",
- [2] = "AIRPLANE",
- [3] = "HELICOPTER",
- [4] = "SHIP",
- [5] = "STRUCTURE",
- }
- ESHGCategory =
- {
- [1] = "AIRPLANE",
- [2] = "HELICOPTER",
- [3] = "GROUND",
- [4] = "SHIP",
- }
- ESHOfield =
- {
- [1] = "time",
- [2] = "coalition",
- [3] = "type",
- [4] = "player",
- [5] = "playerTarget",
- [6] = "typeTarget",
- [7] = "weaponCategory",
- [8] = "weaponFlag",
- }
- StatTable =
- {
- [1] =
- {
- [1] = {},
- [2] = {},
- [3] = {},
- [4] = {},
- },
- [2] =
- {
- [1] = {},
- [2] = {},
- [3] = {},
- [4] = {},
- },
- }
- function SecondsToClock(sSeconds)
- local nSeconds = sSeconds
- if nSeconds == 0 then
- --return nil;
- return "00:00:00";
- else
- nHours = string.format("%02.f", math.floor(nSeconds/3600));
- nMins = string.format("%02.f", math.floor(nSeconds/60 - (nHours*60)));
- nSecs = string.format("%02.f", math.floor(nSeconds - nHours*3600 - nMins *60));
- return nHours..":"..nMins..":"..nSecs
- end
- end
- function eStatHandler:onEvent(e)
- if e.initiator then
- local eid = e.initiator.id_
- local uGroup = e.initiator:getGroup()
- local uCoa = uGroup:getCoalition()
- local gCategory = uGroup:getCategory() + 1
- local uType = e.initiator:getTypeName()
- local uName = e.initiator:getName()
- --if e.initiator:getPlayerName() == nil then
- local uPlayer = "AI"
- --else
- --local uPlayer = e.initiator:getPlayerName()
- --end
- if e.id == world.event.S_EVENT_HIT then
- local etid = e.target.id_
- local eTarget = e.target
- local eTargetType = eTarget:getTypeName()
- local uTargetGroup = eTarget:getGroup()
- local uTargetCoa = uTargetGroup:getCoalition()
- local gTargetCategory = uTargetGroup:getCategory() + 1
- local wDesc = e.weapon:getDesc()
- local wCategory = e.weapon.Category[wDesc[category]]
- local wFlag = e.weapon.flag
- --if eTarget:getPlayerName() == nil then
- local eTargetPlayer = "AI"
- --else
- --local eTargetPlayer = eTarget:getPlayerName()
- --end
- if StatTable[uTargetCoa][gTargetCategory][etid] == nil then
- StatTable[uTargetCoa][gTargetCategory][etid] = {}
- table.remove(StatTable[uTargetCoa][gTargetCategory][etid],5)
- table.remove(StatTable[uTargetCoa][gTargetCategory][etid],6)
- table.remove(StatTable[uTargetCoa][gTargetCategory][etid],7)
- table.remove(StatTable[uTargetCoa][gTargetCategory][etid],8)
- table.insert(StatTable[uTargetCoa][gTargetCategory][etid],5,eTargetPlayer)
- table.insert(StatTable[uTargetCoa][gTargetCategory][etid],6,eTargetType)
- table.insert(StatTable[uTargetCoa][gTargetCategory][etid],7,wCategory)
- table.insert(StatTable[uTargetCoa][gTargetCategory][etid],8,wFlag)
- end
- elseif e.id == world.event.S_EVENT_DEAD
- or e.id == world.event.S_EVENT_EJECTION
- or e.id == world.event.S_EVENT_PILOT_DEAD
- or e.id == world.event.S_EVENT_CRASH then
- if StatTable[uCoa][gCategory][eid] == nil then
- StatTable[uCoa][gCategory][eid] = {}
- table.insert(StatTable[uCoa][gCategory][eid],1,SecondsToClock(timer.getTime()))
- table.insert(StatTable[uCoa][gCategory][eid],2,ESHCoalition[uCoa])
- table.insert(StatTable[uCoa][gCategory][eid],3,uType)
- table.insert(StatTable[uCoa][gCategory][eid],4,uPlayer)
- table.insert(StatTable[uCoa][gCategory][eid],9,"end")
- elseif not StatTable[uCoa][gCategory][eid][9] == "end" then
- table.insert(StatTable[uCoa][gCategory][eid],1,SecondsToClock(timer.getTime()))
- table.insert(StatTable[uCoa][gCategory][eid],2,ESHCoalition[uCoa])
- table.insert(StatTable[uCoa][gCategory][eid],3,uType)
- table.insert(StatTable[uCoa][gCategory][eid],4,uPlayer)
- table.insert(StatTable[uCoa][gCategory][eid],9,"end")
- end
- end
- end
- end
- world.addEventHandler(eStatHandler)
Advertisement
Add Comment
Please, Sign In to add comment