WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Sync code with in-game attack animation? (https://www.wowinterface.com/forums/showthread.php?t=59468)

LudiusMaximus 01-17-23 02:04 AM

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)


All times are GMT -6. The time now is 11:01 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI