View Single Post
01-17-23, 02:04 AM   #1
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 323
Sync code with in-game attack animation?

How can I make my code execute something exactly in the moment the player attacks something?

I tried the COMBAT_LOG_EVENT_UNFILTERED event, but this appears to happen a noticeabe time before the in-game model actually swings at the target and the damage is displayed in-game.

Lua Code:
  1. playerGuid = UnitGUID("player")
  2. local eventFrame = CreateFrame("Frame")
  3. eventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  4. eventFrame:SetScript("OnEvent", function(_, ...)
  5.  
  6.   timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()
  7.   if sourceGUID == playerGuid then
  8.  
  9.     local amount, critical
  10.     if subevent == "SWING_DAMAGE" then
  11.       amount, _, _, _, _, _, critical = select(12, CombatLogGetCurrentEventInfo())
  12.     elseif subevent == "SPELL_DAMAGE" then
  13.       _, _, _, amount, _, _, _, _, _, critical = select(12, CombatLogGetCurrentEventInfo())
  14.     else
  15.       return
  16.     end
  17.  
  18.     -- This comes noticeably earlier than the in-game action takes place.
  19.     -- But I want it to happen exactly at the same time as the in-game action.
  20.     print(amount, critical)
  21.    
  22.   end
  23. end)
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote