I downloaded his addon Damaging and made some visual changes to it. However, as much as I like the addon, it kills me that it is always visible. I want to edit it to make it only show when in combat. It is a very small addon so I will post all the code. My thinking was to make it hide when out of combat when I execute the slash command /lock, but couldn't figure out how to do this.
Anyway, thanks to anyone that can help. Here is the code:
Code:
local current_percent = 100|||Quote:
local p,t,f
local function Damaging_ChatMsg(msg)
DEFAULT_CHAT_FRAME:AddMessage(msg)
end
local function Damaging_GetPC()
--Update the current stored damage modifier
local _,_,_,_,_,percent = UnitRangedDamage("player")
current_percent = ceil(percent * 100)
end
SLASH_DAMAGING1 = '/dmg' --slash command
SlashCmdList.DAMAGING = function(msg)
--Damaging_GetPC()
--chat(current_percent)
if (msg == "lock") then
f:SetMovable(not f:IsMovable()) --invert state
if (f:IsMovable()) then
-- I "shouldn't" do things like this
f:SetScript("OnMouseDown", f.StartMoving)
f:SetScript("OnMouseUp", f.StopMovingOrSizing)
Damaging_ChatMsg("Frame is unlocked")
else
f:SetScript("OnMouseDown", nil)
f:SetScript("OnMouseUp", nil)
Damaging_ChatMsg("Frame is locked")
end
elseif (msg == "hide") then f:Hide()
elseif (msg == "show") then f:Show() end
end
local function Damaging_UpdateText()
Damaging_GetPC()
p:SetText(current_percent.."%")
if (current_percent >= 115) then
p:SetTextColor(0.0, 1.0, 0.0)
t:SetTexture(0.0, 0.0, 0.0, 0.25)
elseif (current_percent >= 106) then
p:SetTextColor(1.0, 1.0, 0.0)
t:SetTexture(0.0, 0.0, 0.0, 0.25)
elseif (current_percent <= 60) then
p:SetTextColor(1.0, 0.0, 0.0)
t:SetTexture(0.0, 0.0, 0.0, 0.25)
else
p:SetTextColor(1.0, 1.0, 1.0)
t:SetTexture(0.0, 0.0, 0.0, 0.25)
end
end
f = CreateFrame("Frame","DamagingFrame2")
p = f:CreateFontString("DamagingFrame2_PC","OVERLAY")
t = f:CreateTexture()
f:RegisterEvent("UNIT_AURA")
f:SetWidth("40")
f:SetHeight("30")
t:SetAllPoints(f)
t:SetTexture(0.0, 0.0, 0.0, 0.25)
p:SetPoint("CENTER", 1.0, 1.0)
p:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
p:SetTextColor(1.0, 1.0, 1.0)
--p:SetText(current_percent)
Damaging_UpdateText()
p:Show()
f:SetPoint("CENTER",1.0,1.0)
f:SetMovable(true)
f:EnableMouse(true)
f:SetScript("OnMouseDown", f.StartMoving)
f:SetScript("OnMouseUp",f.StopMovingOrSizing)
f:SetScript("OnEvent",Damaging_UpdateText)
f:SetScript("OnLoad",Damaging_UpdateText)
f:Show()
I want to edit it to make it only show when in combat.
U should use API UnitAffectingCombat
Like:
Code:
local function Damaging_UpdateText()
Damaging_GetPC()
p:SetText(current_percent.."%")
if (current_percent >= 115) then
p:SetTextColor(0.0, 1.0, 0.0)
t:SetTexture(0.0, 0.0, 0.0, 0.25)
elseif (current_percent >= 106) then
p:SetTextColor(1.0, 1.0, 0.0)
t:SetTexture(0.0, 0.0, 0.0, 0.25)
elseif (current_percent <= 60) then
p:SetTextColor(1.0, 0.0, 0.0)
t:SetTexture(0.0, 0.0, 0.0, 0.25)
else
p:SetTextColor(1.0, 1.0, 1.0)
t:SetTexture(0.0, 0.0, 0.0, 0.25)
end
if (UnitAffectingCombat("player") == 1) then
f:Show();
else f:Hide();
end
end
>> Remove Line 84: f:Show()
sorry I'm not of much use, bored and can't test it|||Thanks. I thought UnitAffectingCombat was what I needed to use. I tried a few things, but couldn't quite get it to work. I will put that code in and test it tonight. Thanks for the help. I plan to learn how to make addons, and I figure messing with these smaller ones is a good way to get my feet wet. Thanks again.
Wow, three "thank you"s in one paragraph, and I haven't even tested it yet :D
- Cognar|||It works . . .|||......
lol|||A more elegant approach would be to do the hiding and showing only when entering and leaving combat. There are two events for that (forget the name) where you can do that.|||Quote:
A more elegant approach would be to do the hiding and showing only when entering and leaving combat. There are two events for that (forget the name) where you can do that.
PLAYER_REGEN_ENABLED (leaving combat), PLAYER_REGEN_DISABLED (just before enter combat)|||Quote:
PLAYER_REGEN_ENABLED (leaving combat), PLAYER_REGEN_DISABLED (just before enter combat)
That's them !|||I was able to get this working the way I wanted when I used UnitAffectingCombat without any issues, but when I tried PLAYER_REGEN_ENABLED/DISABLED I had an issue:
I had to remove f:Hide(); from the Damaging_UpdateText() function because the function is being run repeatedly and PLAYER_REGEN_DISABLED is only present at the start of combat. UnitAffectingCombat works because it is persistent during combat. The trouble with taking out f:Hide() is that the addon is visible at startup.
I figured this would be easy to fix by running f:Hide() onload, but I couldn't figure out how to do this. Please help of you can. I am learning a lot from this.
- Cogs|||Quote:
I was able to get this working the way I wanted when I used UnitAffectingCombat without any issues, but when I tried PLAYER_REGEN_ENABLED/DISABLED I had an issue:
I had to remove f:Hide(); from the Damaging_UpdateText() function because the function is being run repeatedly and PLAYER_REGEN_DISABLED is only present at the start of combat. UnitAffectingCombat works because it is persistent during combat. The trouble with taking out f:Hide() is that the addon is visible at startup.
I figured this would be easy to fix by running f:Hide() onload, but I couldn't figure out how to do this. Please help of you can. I am learning a lot from this.
- Cogs
To hide this when it loads, just swap the last line in your code f:Show() with f:Hide()
Then you should be able to show/hide when the REGEN messages arrives, and it should be hidden at startup.
No comments:
Post a Comment