Page 1 of 1

Looking for a Heal Target else Heal Self macro

PostPosted: Mon Mar 21, 2016 4:43 pm
by BarbarianBill
So here is the situation I'm in. I'm a Priest trying to find a way to make a macro that can Heal if a Target is selected, else Heal myself, and then target the last target. Reason being is because I used the alt-keybinds (which of course allows me to heal myself) for my bottomleft action bar. Now I can't really self-heal with a no-target self-cast like retail WoW, so I'm trying to find a macro that can do this. Yes I do know about healing addons along with grid (which I do have), but I want to do it for quick situations so I can bind them to my mouse buttons and help cast on people who are not in my party.

Any help would be greatly appreciated. Any snarky remarks on how I want to play will just be ignored.

Thank you guys!

Re: Looking for a Heal Target else Heal Self macro

PostPosted: Mon Mar 21, 2016 5:54 pm
by BarbarianBill
Nevermind, after some time I figured it out.

Code: Select all
/sstt Heal
/run C=CastSpellByName; A="Heal" if UnitIsFriend("player","target") then C(A) else if not UnitIsFriend("player","target") then TargetUnit("player")end C(A); TargetLastTarget()end


This is what it does
1) if Target is friendly then stay on targets frame/portrait
2) if Target is not friendly then TargetSelf->Heal->TargetLastTarget
3) if no target at all just self heal

Re: Looking for a Heal Target else Heal Self macro

PostPosted: Mon Mar 21, 2016 6:19 pm
by Youfie
Hey,

I'm no macro expert, but I was wondering : isn't the second "if not UnitIsFriend("player", "target")" redundant? I mean, since you already got one earlier, wouldn't a "if" be enough, rather than a "else if" in this situation?

If I'm mistaken I'd like to know why, would help me with my own scripts :).

Cheers!

Re: Looking for a Heal Target else Heal Self macro

PostPosted: Mon Mar 21, 2016 6:34 pm
by BarbarianBill
Youfie wrote:Hey,

I'm no macro expert, but I was wondering : isn't the second "if not UnitIsFriend("player", "target")" redundant? I mean, since you already got one earlier, wouldn't a "if" be enough, rather than a "else if" in this situation?

If I'm mistaken I'd like to know why, would help me with my own scripts :).

Cheers!

Haha, np
I'm no macro expert myself, I just spent an hour trying to figure this out myself.

The thing is that if I remove the "if not UnitIsFriend("player", "target")" and just leave it as "else TargetUnit("player")" I get a scripting error.

If I put "if TargetUnit("player")" then it expects me to already have myself targeted which wasn't my intent to begin with.

If I totally misunderstood you please let me know.

Re: Looking for a Heal Target else Heal Self macro

PostPosted: Mon Mar 21, 2016 6:39 pm
by Youfie
You understood me perfectly, I had no idea just using a simple "else" wouldn't work. LUA has its mysteries I guess, if someone knows more about that matter, please share :).

Re: Looking for a Heal Target else Heal Self macro

PostPosted: Mon Mar 21, 2016 6:41 pm
by Renew
Code: Select all
/run if UnitIsFriend("player","target") then CastSpellByName("Heal") else CastSpellByName("Heal",1) end


yw

Re: Looking for a Heal Target else Heal Self macro

PostPosted: Mon Mar 21, 2016 10:42 pm
by Dreez
Youfie wrote:Hey,

I'm no macro expert, but I was wondering : isn't the second "if not UnitIsFriend("player", "target")" redundant? I mean, since you already got one earlier, wouldn't a "if" be enough, rather than a "else if" in this situation?

If I'm mistaken I'd like to know why, would help me with my own scripts :).

Cheers!

Yes, it is redundant.

Code: Select all
if UnitIsFriend("player", "target")then CastSpellByName("Heal") else CastSpellByName("Heal", 1)end

is sufficient.

Also note that there's a difference between "elseif" and "else if"

here's an example:
Code: Select all
if UnitIsFriend("player", "target") then
   CastSpellByName("Heal")
else
   if UnitIsEnemy("player", "target") then
      CastSpellByName("Heal", 1)
   end
end

compared to
Code: Select all
if UnitIsFriend("player", "target") then
   CastSpellByName("Heal")
elseif UnitIsEnemy("player", "target") then
      CastSpellByName("Heal", 1)
end

both do the exact same thing, however
Code: Select all
if UnitIsFriend("player", "target") then
   CastSpellByName("Heal")
else
      CastSpellByName("Heal", 1)
end

will also heal yourself if your current target neither is an enemy nor a friend (not relevant in this specific example)

Well basically it is the same, you'll just need one more "end" when using "else if"

Re: Looking for a Heal Target else Heal Self macro

PostPosted: Tue Mar 22, 2016 9:40 am
by Youfie
Ok, thanks for the heads up :).