Advertisement
Guest User

Untitled

a guest
Dec 20th, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. _addon.name = 'THTest'
  2. _addon.author = 'Thorny'
  3. _addon.version = '1.00-w'
  4. _addon.commands = {'tht'} --No commands ported yet
  5. --addon.link = 'https://github.com/ThornyFFXI/'
  6.  
  7. require('tables')
  8. config = require('config')
  9. texts = require('texts')
  10.  
  11. local currentTarget = {}
  12. local globalProcCount = T{}
  13. local currentPlayerTH = 15
  14.  
  15. local filePath
  16. local backupPath
  17.  
  18. windower.register_event("load", function (...)
  19. local time = os.date('*t')
  20.  
  21. local folderName = "logs"
  22. if not windower.dir_exists(windower.addon_path..folderName) then
  23. windower.create_dir(windower.addon_path..folderName)
  24. end
  25.  
  26. local fileName = ('%04d%02d%02d_%02d%02d%02d.csv'):format(time.year, time.month, time.day, time.hour, time.min, time.sec)
  27. filePath = windower.addon_path..string.format('%s/%s', folderName, fileName)
  28. fileName = ('%04d%02d%02d_%02d%02d%02d_missed.csv'):format(time.year, time.month, time.day, time.hour, time.min, time.sec)
  29. backupPath = windower.addon_path..string.format('%s/%s', folderName, fileName)
  30.  
  31. if (not windower.file_exists(filePath)) then
  32. local file = io.open(filePath, 'w')
  33. file:write('"Timestamp","Mob TH Level","Player TH Level","Proc Index","Proc Crit","First Hit Crit","First Hit Land","First Hit Damage"\n')
  34. file:close()
  35. end
  36. if (not windower.file_exists(backupPath)) then
  37. local file = io.open(filePath, 'w')
  38. file:write('"Timestamp","Mob TH Level","Player TH Level","Proc Index","Proc Crit","First Hit Crit","First Hit Land","First Hit Damage"\n')
  39. file:close()
  40. end
  41. end)
  42.  
  43. windower.register_event('action', function(act)
  44. if act['actor_id'] == windower.ffxi.get_player()['id'] then
  45. if act['category'] == 1 then
  46. local target = act['targets'][1]
  47. if target then
  48. local targetId = target['id']
  49. if targetId ~= currentTarget.Id then
  50. currentTarget = {
  51. Id = targetId,
  52. TH = math.min(currentPlayerTH, 8),
  53. Name = windower.ffxi.get_mob_by_id(targetId)['name'],
  54. Index = windower.ffxi.get_mob_by_id(targetId)['index'],
  55. ProcCount = T{},
  56. }
  57. end
  58.  
  59. local currentTH = currentTarget.TH
  60. local localProcCount = currentTarget.ProcCount
  61. if (localProcCount[currentTH] == nil) then
  62. localProcCount[currentTH] = { HitCount=1, ProcCount=0 }
  63. else
  64. localProcCount[currentTH].HitCount = localProcCount[currentTH].HitCount + 1
  65. end
  66.  
  67. if (globalProcCount[currentTH] == nil) then
  68. globalProcCount[currentTH] = { HitCount=1, ProcCount=0 }
  69. else
  70. globalProcCount[currentTH].HitCount = globalProcCount[currentTH].HitCount + 1
  71. end
  72.  
  73. local procIndex = 0
  74. local wasCrit = T{}
  75. local wasHit = T{}
  76. local hitDamage = T{}
  77. for index,action in ipairs(target.actions) do
  78. wasCrit[index] = (action.effect == 2)
  79. wasHit[index] = ((action.reaction ~= 1) and (action.effect ~= 2))
  80. hitDamage[index] = action.param
  81. if (action.has_add_effect) then
  82. if (action.add_effect_message == 603) then
  83. procIndex = index
  84. currentTarget.TH = action.add_effect_param
  85. localProcCount[currentTH].ProcCount = localProcCount[currentTH].ProcCount + 1
  86. globalProcCount[currentTH].ProcCount = globalProcCount[currentTH].ProcCount + 1
  87. end
  88. end
  89. end
  90.  
  91. local procCrit = 0
  92. if (procIndex ~= 0) then
  93. procCrit = (wasCrit[procIndex] and 1 or 0)
  94. end
  95.  
  96. local output = string.format('%u,%u,%u,%u,%u,%u,%u,%u\n',
  97. os.time(),
  98. currentTH,
  99. currentPlayerTH,
  100. procIndex,
  101. procCrit,
  102. wasCrit[1] and 1 or 0,
  103. wasHit[1] and 1 or 0,
  104. hitDamage[1])
  105.  
  106. local file = io.open(filePath, 'a')
  107. if (file) then
  108. file:write(output)
  109. file:close()
  110. else
  111. file = io.open(backupPath, 'a')
  112. if file then
  113. file:write(output)
  114. file:close()
  115. else
  116. print(string.format('Failed to open file and backup file. Data Point:%s', output))
  117. end
  118. end
  119. end
  120. end
  121. end
  122. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement