Quantcast
Detecting cast on me - WoWInterface
Thread Tools Display Modes
01-07-21, 07:39 AM   #1
n00bsteam
A Murloc Raider
Join Date: Feb 2017
Posts: 8
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
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)
  Reply With Quote
01-07-21, 09:04 AM   #2
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 982
huh, did you get it from here. it looks familiar

https://www.wowinterface.com/forums/...php?t=55218#11
  Reply With Quote
01-07-21, 09:08 AM   #3
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 982
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")
  Reply With Quote
01-07-21, 01:06 PM   #4
n00bsteam
A Murloc Raider
Join Date: Feb 2017
Posts: 8
yeh, looks like i take some from there, but code from you thread doesnt work to
  Reply With Quote
01-07-21, 02:16 PM   #5
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 982
uhh never mind. have a good day
  Reply With Quote
01-07-21, 05:59 PM   #6
n00bsteam
A Murloc Raider
Join Date: Feb 2017
Posts: 8
Originally Posted by Ketho View Post
uhh never mind. have a good day
you have no idea how help me?
  Reply With Quote
01-09-21, 12:32 AM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,026
It requires NamePlates to be turned on and to be in range to have one for the mob in question.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
01-11-21, 12:10 AM   #8
n00bsteam
A Murloc Raider
Join Date: Feb 2017
Posts: 8
Originally Posted by SDPhantom View Post
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.
  Reply With Quote
01-11-21, 12:39 PM   #9
n00bsteam
A Murloc Raider
Join Date: Feb 2017
Posts: 8
ok, i fix it.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Detecting cast on me

Thread Tools
Display Modes

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