View Single Post
06-17-20, 11:40 AM   #9
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
All player GUIDs are unique and do not change as long as the character does not change faction or realm. I'm pretty sure they stick if you only name change, but I could be wrong.

All other GUIDs are designated on spawn. Every single object, item, npc, anything else in the game receives a unique GUID upon spawn, including your pet, since it's a controllable npc. When your pet disappears, it will get a new GUID when you see it again.

Use the event UNIT_PET with the first arg being "player" to get the new GUID each time.

Also, you were missing an end, you need to make playerGUID and petGUID a local to prevent other addons from changing them, and the entering world event has login and reload boolean payloads so you don't have to unregister that event.

Lua Code:
  1. local playerGUID, petGUID
  2. local function DummyFrame_OnEvent(self, event, ...)
  3.     if event == "PLAYER_ENTERING_WORLD" then
  4.         local login, reload = ...
  5.         if login or reload then
  6.             playerGUID = UnitGUID("player")
  7.             petGUID = UnitGUID("pet")
  8.         end
  9.     elseif event == "UNIT_PET" then
  10.         local unit = ...
  11.         if unit == "player" then
  12.             petGUID = UnitGUID("pet")
  13.         end
  14.     elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
  15.         local timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()
  16.         if (sourceGUID == playerGUID or sourceGUID == petGUID) and (destGUID ~= petGUID) and (destGUID ~= playerGUID) then
  17.             print("sourceGUID "..sourceGUID)
  18.             print("destGUID "..destGUID)
  19.             print(timestamp.."|n")
  20.         end
  21.     end
  22. end
  23. DummyFrame:SetScript("OnEvent", DummyFrame_OnEvent)
  Reply With Quote