Thread Tools Display Modes
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: 321
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

WoWInterface » Developer Discussions » Lua/XML Help » Sync code with in-game attack animation?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off