Help with script

Re: Help with script

by LYQ » Fri Oct 23, 2015 1:19 pm

I'm not at home so can't test any of this, mine were just assumptions

but yeah checking if there's actually a target and so on is a good point

the loop in your first version was just for 2 frames so I doubt that it would've been a better option than simply writing it, I'm pretty sure I've read somewhere in code complete that based on test results compiling a loop will only be superior than writing it out if the loop will loop more than 100 times (or something like that) - but then again, if I had to check my code my loops barely reach that amount :D
I just thought yours was over the top since on hiding you implemented the loop for jsut 2 elements, but when you've let the frames be shown again you didn't :D and wrote it out - so yeah, one or the other

but yeah general I think we both went a little to deep into this :D let the OP decide if that's really what he wants^^
LYQ / Virose
Talentsaver (viewtopic.php?f=63&t=15429) - Totemtimers Enhanced (viewtopic.php?f=63&t=24422)
NostalriusAcceptTrade (viewtopic.php?f=63&t=31729)
User avatar
LYQ
Sergeant Major
Sergeant Major
 

Re: Help with script

by modernist » Fri Oct 23, 2015 1:24 pm

indeed! turned into a lunchtime project
modernist
Sergeant Major
Sergeant Major
 

Re: Help with script

by jakeadams » Fri Oct 23, 2015 1:26 pm

Well, I have tested LYG's and that works just fine.

On thing though, I know I didn't specify this: I realized that one thing that's annoying is that when I am out of combat and use spells, then my unitframe is still hiding.. So after buffing up I will have no idea of when I am at full health.

Can I just add another "else if" about not being at max health and then hide?

Edit:
I am just happy to find someone who can help me with it, I don't want to use all your time ;)
User avatar
jakeadams
Sergeant
Sergeant
 

Re: Help with script

by modernist » Fri Oct 23, 2015 1:34 pm

Code: Select all
local f = CreateFrame("frame");
f:RegisterEvent("UNIT_HEALTH")
f:RegisterEvent("UNIT_MANA")
f:SetScript('OnEvent', function()
  if arg1 ~= "player" then return end
  local hv =   UnitHealth'player'    local pv = UnitMana'player'
  local hmax = UnitHealthMax'player' local pmax = UnitManaMax'player'
  if (UnitAffectingCombat("player") or (hv ~= hmax or pv ~= pmax)) and not DUF_PlayerFrame:IsVisible() then
    DUF_PlayerFrame:Show()
    DUF_PetFrame:Show()
    DUF_TargetFrame:Show()
    DUF_TargetOfTargetFrame:Show()
  elseif hv == hmax and pv == pmax and DUF_PlayerFrame:IsVisible() then
    DUF_PlayerFrame:Hide()
    DUF_PetFrame:Hide()
    DUF_TargetFrame:Hide()
    DUF_TargetOfTargetFrame:Hide()
  end
end)
modernist
Sergeant Major
Sergeant Major
 

Previous

Return to Addons & macros