View Full Version : Do macro if an enemy is selected?
justalookin
11-05-2007, 09:05 PM
I just can't figure out how to put this if statement into a macro - I have a macro which does what i want, but i only wish to be able to cast it if an enemy is selected.
Any clues?
Tunga
11-05-2007, 09:17 PM
Depends on the macro. To cast a spell:
/cast [exists] SpellName
I think that should work.
justalookin
12-05-2007, 12:46 AM
Thanks for the help - i should really explain what I'm trying to do and give code for my work so far :)
I have this so far:
/script SetRaidTarget("target", 1)
/cast Polymorph(Rank 3)
/script SendChatMessage("SHEEPING Level " .. UnitLevel("target") .. " %t", "party");
Basically what I want to happen is I set the raid icon (done), cast to a sheep (can do), and announce the victim to the party chat (done).
What i'd also like to happen is ONLY output that info to the party chat if the cast has been a sucess. At the moment if I have no enemy selected and accidently click the macro button, it outputs "SHEEPING Level 0 <no target>" to the party chat.
I don't wish to annoy anyone with this macro, so only want to announce if I've selected the target and then sheeped.
Any further help? Sorry I didn't post this much info before, i was still working on it :)
Tunga
12-05-2007, 02:10 AM
Try this:
/cast [exists] Polymorph
/script if(UnitExists("target")) then SetRaidTarget("target", 1); SendChatMessage("SHEEPING Level " .. UnitLevel("target") .. " %t", "party"); end
I changed the line order to try to save characters since then you only need one if statement. But basically you should be able to see what I'm doing here, it's a simple if...then...else with the UnitExists function, and you can adjust it however you like. Hope that helps.
justalookin
12-05-2007, 04:49 PM
Tunga, that's exactly what i was after - it works perfectly :)
Much neater and more compact than what I was doing to boot! :grin:
Tunga
13-05-2007, 12:23 AM
Was expecting there to be a typo in there somewhere, glad it works :) .
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.