WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Need help with spell activation overlay (https://www.wowinterface.com/forums/showthread.php?t=58448)

VeenixO 12-09-20 12:59 PM

Need help with spell activation overlay
 
Hi all, new here!

First time trying to make an addon and wanted to make something that in my mind seems simple.
Seems that it's not as simple as I thought.

Basically I want to make an addon that shows a texture when Hammer of Wrath procs or is useable (like when Blade of Justice procs). This is the code I have atm but it doesn't seem to work.

local f = CreateFrame("Frame")
local spellID = 24275 --Hammer of Wrath

f:RegisterEvent("SPELL_ACTIVATION_OVERLAY_SHOW")
f:RegisterEvent("SPELL_ACTIVATION_OVERLAY_HIDE")

f:SetScript("OnEvent", function(self,event, spellID, ...)
if event == "SPELL_ACTIVATION_OVERLAY_SHOW" then
if (arg1 == "24275") then
print("Hello, WoW!")
end
end

if event == "SPELL_ACTIVATION_OVERLAY_HIDE" then
if (arg1 == "24275") then
print("Bye")
end
end

end)

Could anyone give me some advice on how to check when Hammer of Wrath procs/is useable?

Thanks alot in advance!

Vrul 12-09-20 01:32 PM

You are referencing arg1 when it should be spellID and you are checking the wrong events. Give this a shot:
Lua Code:
  1. local SPELL_ID = 24275  -- Hammer of Wrath
  2.  
  3. local frame = CreateFrame("Frame")
  4. frame:SetScript("OnEvent", function(self, event, spellID)
  5.     if event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" then
  6.         if spellID == SPELL_ID then
  7.             print("Hello, WoW!")
  8.         end
  9.     elseif event == "SPELL_ACTIVATION_OVERLAY_GLOW_HIDE" then
  10.         if spellID == SPELL_ID then
  11.             print("Bye")
  12.         end
  13.     end
  14. end)
  15. frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
  16. frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE")

VeenixO 12-09-20 02:36 PM

Quote:

Originally Posted by Vrul (Post 337850)
You are referencing arg1 when it should be spellID and you are checking the wrong events. Give this a shot:
Lua Code:
  1. local SPELL_ID = 24275  -- Hammer of Wrath
  2.  
  3. local frame = CreateFrame("Frame")
  4. frame:SetScript("OnEvent", function(self, event, spellID)
  5.     if event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" then
  6.         if spellID == SPELL_ID then
  7.             print("Hello, WoW!")
  8.         end
  9.     elseif event == "SPELL_ACTIVATION_OVERLAY_GLOW_HIDE" then
  10.         if spellID == SPELL_ID then
  11.             print("Bye")
  12.         end
  13.     end
  14. end)
  15. frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
  16. frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE")

Seems to do the trick! Thank you ^^ Now just need to figure out how to make a texture appear but I'll try that on my own first ^^

VeenixO 12-09-20 03:34 PM

Alright seems like I know nothing about textures in wow.
If I understand correctly I need an xml file to show textures?
How would I go about showing a texture whenever the spell activation overlay glow happens for hammer of wrath and make it dissapear when the overlay is hidden?
Also is there a way to make the texture 50% transparent when out of range?

Don't really understand how to link xml and lua, sorry very new to this haha

Xrystal 12-09-20 05:02 PM

First off .. a link worth visiting and looking at the introduction pages and then start with something simple.
https://wow.gamepedia.com/Wowpedia:I..._customization

You can use xml or lua to create texture objects.
These are the pages that explain the different elements to create a texture for a frame

https://wow.gamepedia.com/UIOBJECT_Frame
https://wow.gamepedia.com/API_Frame_CreateTexture
https://wow.gamepedia.com/API_Texture_SetTexture

Start with those and make sure you look at SetPoint ( Anchoring ) to place the frame on the screen in relation to another frame.

There are options to Hide() and Show() any frame but they can't be done during combat without special secure code access, I don't think you're ready for that quite yet but you can use it for non combat testing just to see how it works. SetAlpha(1) will make the frame visible and SetAlpha(0) will make it invisible with numbers between variable transparency.

Take your time and slowly expand your knowledge as and when you find the need/wish.

I'm sure others will provide what knowledge they have to assist you in more detail but Vruls response is a good starting point to expand on.

Quote:

Originally Posted by VeenixO (Post 337853)
Alright seems like I know nothing about textures in wow.
If I understand correctly I need an xml file to show textures?
How would I go about showing a texture whenever the spell activation overlay glow happens for hammer of wrath and make it dissapear when the overlay is hidden?
Also is there a way to make the texture 50% transparent when out of range?

Don't really understand how to link xml and lua, sorry very new to this haha


Vrul 12-09-20 06:46 PM

Lua Code:
  1. local SPELL_ID = 24275  -- Hammer of Wrath
  2. local SPELL_NAME = GetSpellInfo(SPELL_ID)
  3. local UPDATE_INTERVAL = 0.1
  4.  
  5. local frame = CreateFrame("Frame", nil, UIParent)
  6. frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  7. frame:SetSize(64, 64)
  8. frame:Hide()
  9.  
  10. local texture = frame:CreateTexture()
  11. texture:SetAllPoints(frame)
  12. texture:SetTexture(GetSpellTexture(SPELL_ID))
  13.  
  14. frame:SetScript("OnEvent", function(self, event, spellID)
  15.     if event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" then
  16.         if spellID == SPELL_ID then
  17.             frame:Show()
  18.         end
  19.     elseif event == "SPELL_ACTIVATION_OVERLAY_GLOW_HIDE" then
  20.         if spellID == SPELL_ID then
  21.             frame:Hide()
  22.         end
  23.     end
  24. end)
  25. frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
  26. frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE")
  27.  
  28. local timer = UPDATE_INTERVAL
  29. frame:SetScript("OnUpdate", function(self, elapsed)
  30.     timer = timer + elapsed
  31.     if timer < UPDATE_INTERVAL then return end
  32.     timer = 0
  33.  
  34.     if IsSpellInRange(SPELL_NAME, "target") == 1 then
  35.         frame:SetAlpha(1)
  36.     else
  37.         frame:SetAlpha(0.5)
  38.     end
  39. end)
  40.  
  41. frame:SetScript("OnHide", function(self)
  42.     timer = UPDATE_INTERVAL
  43. end)

VeenixO 12-10-20 04:21 AM

Quote:

Originally Posted by Xrystal (Post 337854)
First off .. a link worth visiting and looking at the introduction pages and then start with something simple.
https://wow.gamepedia.com/Wowpedia:I..._customization

You can use xml or lua to create texture objects.
These are the pages that explain the different elements to create a texture for a frame

https://wow.gamepedia.com/UIOBJECT_Frame
https://wow.gamepedia.com/API_Frame_CreateTexture
https://wow.gamepedia.com/API_Texture_SetTexture

Start with those and make sure you look at SetPoint ( Anchoring ) to place the frame on the screen in relation to another frame.

There are options to Hide() and Show() any frame but they can't be done during combat without special secure code access, I don't think you're ready for that quite yet but you can use it for non combat testing just to see how it works. SetAlpha(1) will make the frame visible and SetAlpha(0) will make it invisible with numbers between variable transparency.

Take your time and slowly expand your knowledge as and when you find the need/wish.

I'm sure others will provide what knowledge they have to assist you in more detail but Vruls response is a good starting point to expand on.

Thank you for the link! Will come in handy ^^

VeenixO 12-10-20 04:21 AM

Quote:

Originally Posted by Vrul (Post 337855)
Lua Code:
  1. local SPELL_ID = 24275  -- Hammer of Wrath
  2. local SPELL_NAME = GetSpellInfo(SPELL_ID)
  3. local UPDATE_INTERVAL = 0.1
  4.  
  5. local frame = CreateFrame("Frame", nil, UIParent)
  6. frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  7. frame:SetSize(64, 64)
  8. frame:Hide()
  9.  
  10. local texture = frame:CreateTexture()
  11. texture:SetAllPoints(frame)
  12. texture:SetTexture(GetSpellTexture(SPELL_ID))
  13.  
  14. frame:SetScript("OnEvent", function(self, event, spellID)
  15.     if event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" then
  16.         if spellID == SPELL_ID then
  17.             frame:Show()
  18.         end
  19.     elseif event == "SPELL_ACTIVATION_OVERLAY_GLOW_HIDE" then
  20.         if spellID == SPELL_ID then
  21.             frame:Hide()
  22.         end
  23.     end
  24. end)
  25. frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
  26. frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE")
  27.  
  28. local timer = UPDATE_INTERVAL
  29. frame:SetScript("OnUpdate", function(self, elapsed)
  30.     timer = timer + elapsed
  31.     if timer < UPDATE_INTERVAL then return end
  32.     timer = 0
  33.  
  34.     if IsSpellInRange(SPELL_NAME, "target") == 1 then
  35.         frame:SetAlpha(1)
  36.     else
  37.         frame:SetAlpha(0.5)
  38.     end
  39. end)
  40.  
  41. frame:SetScript("OnHide", function(self)
  42.     timer = UPDATE_INTERVAL
  43. end)

Thank you for helping sm! <3

VeenixO 12-10-20 10:20 AM

Alright, so tried to do the final piece of the addon which is checking for cooldown.
Here is the code, it seems to not work all the time and I got no clue what's wrong with it.
Do I have to check for cds in the update script?

local SPELL_ID = 24275 -- Hammer of Wrath
local SPELL_NAME = GetSpellInfo(SPELL_ID)
local UPDATE_INTERVAL = 0.1

local frame = CreateFrame("Frame", nil, UIParent)
frame:SetPoint("CENTER", UIParent, "CENTER", 0, -200)
frame:SetSize(64, 64)
frame:Hide()

local texture = frame:CreateTexture()
texture:SetAllPoints(frame)
texture:SetTexture([[Interface\AddOns\PallyProc\Textures\HolyGlow.tga]])

frame:SetScript("OnEvent", function(self, event, spellID)
if event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" then
if spellID == SPELL_ID and HasFullControl() and IsUsableSpell(SPELL_NAME) and GetSpellCooldown(SPELL_NAME)==0 then
frame:Show()
else
frame:Hide()
end
elseif event == "SPELL_ACTIVATION_OVERLAY_GLOW_HIDE" then
if spellID == SPELL_ID then
frame:Hide()
end
end
end)
frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
frame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE")
frame:RegisterEvent("SPELL_UPDATE_COOLDOWN")

local timer = UPDATE_INTERVAL
frame:SetScript("OnUpdate", function(self, elapsed)
timer = timer + elapsed
if timer < UPDATE_INTERVAL then return end
timer = 0

if IsSpellInRange(SPELL_NAME, "target") == 1 then
frame:SetAlpha(1)
else
frame:SetAlpha(0.5)
end
end)

frame:SetScript("OnHide", function(self)
timer = UPDATE_INTERVAL
end)

VeenixO 12-11-20 07:38 AM

Little update, I seem to have figured out that the proc event won't update when there is a cooldown so is there any event that triggers when a spell is usable or goes on cooldown? I head something about combat log unfiltered but can't find how to properly use it so it triggers on Hammer of Wrath becoming usable and being used. Any clues?


All times are GMT -6. The time now is 10:49 AM.

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