WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Player died event (https://www.wowinterface.com/forums/showthread.php?t=58318)

ragunragun 10-18-20 05:45 PM

Player died event
 
Hi,

Im trying to play a sound on players death, but it does not work for me

Lua Code:
  1. local function OnEvent(self, event, ...)
  2.  
  3. if event == "COMBAT_LOG_EVENT_UNFILTERED" then
  4.            
  5. local Event = select(2, ...)
  6. local sourceGUID = select(4, ...)
  7. local GUID = select(8, ...)
  8. local SpellName = select(13, ...)
  9. local EventType = select(15, ...)
  10.  
  11. if Event == "UNIT_DIED" then
  12. if GUID == UnitGUID("player") then
  13.  
  14. a.Sound(SoundPackValue("player_died"))
  15. end
  16. end
  17. end

and every time I buff myself

Lua Code:
  1. if Event == "SPELL_AURA_APPLIED" and GUID == UnitGUID("player") then
  2. if EventType == "BUFF" then
  3.  
  4. a.Sound(SoundPackValue("buff_on_self"))
  5.  
  6. end
  7. end

Could you please help me understand why doesn't it work and correct me?

Thank you so much for help.

Ketho 10-18-20 06:02 PM

You need to use CombatLogGetCurrentEventInfo() and you should post your full code if you want to get better help with your code
https://wow.gamepedia.com/COMBAT_LOG_EVENT
Lua Code:
  1. local playerGUID = UnitGUID("player")
  2.  
  3. local f = CreateFrame("Frame")
  4. f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  5. f:SetScript("OnEvent", function(self, event)
  6.     self:OnEvent(event, CombatLogGetCurrentEventInfo())
  7. end)
  8.  
  9. function f:OnEvent(event, ...)
  10.     local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = ...
  11.  
  12.     if subevent == "UNIT_DIED" and destGUID == playerGUID then
  13.         print("You died.")
  14.     end
  15. end

As for just the player dying, that can be easier done with PLAYER_DEAD
Lua Code:
  1. local function OnEvent(self, event, ...)
  2.     print("You died.")
  3. end
  4.  
  5. local f = CreateFrame("Frame")
  6. f:RegisterEvent("PLAYER_DEAD")
  7. f:SetScript("OnEvent", OnEvent)

ragunragun 10-19-20 08:19 AM

Works like a charm! Thank you! :banana:


All times are GMT -6. The time now is 06:59 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI