WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Detecting cast on me (https://www.wowinterface.com/forums/showthread.php?t=58530)

n00bsteam 01-07-21 07:39 AM

Detecting cast on me
 
Hello guys! Can u help me with some code, it didnt work, i'm new in lua :(
Looks like table guids allways clear :confused:
Lua Code:
  1. local f = CreateFrame("Frame")
  2.     local guids = {}
  3.     f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  4.     f:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
  5.     f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  6.     f:SetScript("OnEvent", function(self, event, ...)
  7.         if event == "NAME_PLATE_UNIT_ADDED" then
  8.             local unit = ...
  9.             guids[UnitGUID(unit)] = unit
  10.           elseif event == "NAME_PLATE_UNIT_REMOVED" then
  11.             local unit = ...
  12.             guids[UnitGUID(unit)] = nil
  13.         end
  14.         local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellId, spellName, spellSchool = CombatLogGetCurrentEventInfo()
  15.         if subevent == "SPELL_CAST_START" then
  16.             local unit = guids[sourceGUID]
  17.             if unit and UnitIsUnit(unit.."target", "player") and bit.band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) > 0 then
  18.                 print( format("%s cast %s on me", sourceName, spellID) )
  19.             end
  20.         end
  21.     end)

Ketho 01-07-21 09:04 AM

huh, did you get it from here. it looks familiar

https://www.wowinterface.com/forums/...php?t=55218#11

Ketho 01-07-21 09:08 AM

Lua Code:
  1. local guids = {}
  2. local f = CreateFrame("Frame")
  3.  
  4. function f:NAME_PLATE_UNIT_ADDED(unit)
  5.     guids[UnitGUID(unit)] = unit
  6. end
  7.  
  8. function f:NAME_PLATE_UNIT_REMOVED(unit)
  9.     guids[UnitGUID(unit)] = nil
  10. end
  11.  
  12. function f:COMBAT_LOG_EVENT_UNFILTERED()
  13.     local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, _, destGUID, destName, _, _, spellID, spellName = CombatLogGetCurrentEventInfo()
  14.     if subevent == "SPELL_CAST_START" then
  15.         local unit = guids[sourceGUID]
  16.         if unit and UnitIsUnit(unit.."target", "player") and bit.band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) > 0 then
  17.             print( format("%s is casting %s on me", sourceName, GetSpellLink(spellID)) )
  18.         end
  19.     end
  20. end
  21.  
  22. f:SetScript("OnEvent", function(self, event, ...)
  23.     f[event](self, ...)
  24. end)
  25.  
  26. f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  27. f:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
  28. f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")

n00bsteam 01-07-21 01:06 PM

yeh, looks like i take some from there, but code from you thread doesnt work to :(

Ketho 01-07-21 02:16 PM

uhh never mind. have a good day

n00bsteam 01-07-21 05:59 PM

Quote:

Originally Posted by Ketho (Post 338216)
uhh never mind. have a good day

you have no idea how help me?

SDPhantom 01-09-21 12:32 AM

It requires NamePlates to be turned on and to be in range to have one for the mob in question.

n00bsteam 01-11-21 12:10 AM

Quote:

Originally Posted by SDPhantom (Post 338228)
It requires NamePlates to be turned on and to be in range to have one for the mob in question.

Yes, everything is so, when testing in a duel with another player, it appears in the guid table but disappears almost immediately, I don’t understand what it’s connected with, if you turn off and on the nameplates, it appears in the table again, but at the start of the cast it always not present, so the trigger does not work.

n00bsteam 01-11-21 12:39 PM

ok, i fix it.


All times are GMT -6. The time now is 12:08 AM.

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