in your browser.
[Macro] Whisper same target to warn of incoming CC
Return to board index
I used to have a macro for my hex, that would whisper all those who were targeting my target that it would be hex'd soon and to change target.
I server transfered, and lost all my macros... I've redone all from memory, but that one I have yet to find. I stole it from a mage forum somewhere but can't seem to locate it again.
Anyone know of what i speak?
Whatever it is would have to loop through everyone in your party or raid and check what their target is and then whisper them if they're targeting your target.
local m = "Hexing your target!"
if GetNumRaidMembers() then
for r=1,40 do
local ru = "raid"..r
if UnitExists(ru) and UnitIsUnit("target",ru.."target") then
elseif GetNumPartyMembers() then
for p=1,4 do
local pu = "party"..p
if UnitExists(pu) and UnitIsUnit("target",pu.."target") then
That's more or less how it would have to go. I drycoded that and didn't make any attempts at optimization or minimizing.
Another way to write it to make it only have one SendChatMessage line would be to save all the units to whisper in a table and then loop through that at the end; but, that's three loops instead of two (granted only 2 would ever be run; or 1 in this example).
/run local r,_=GetNumRaidMembers()>0 and"raid"or"party"for i=1,40 do _=UnitIsUnit("target",r..i.."target")and SendChatMessage("Hey, you're targeting the same unit as I am!","WHISPER",nil,UnitName(r..i))end
Ah, thanks much you guys!
had a couple guildmates impressed by it and never got around to sharing it with them =D
Oh good call on condensing the loops. I guess an invalid unit just returns nil for UnitIsUnit. Very pro
That is the most elegant solution I've ever seen to one of the bigger (but more preventable) problems in dungeons and raids. Bravo!
I agree it's a very nice/condensed script, but I don't really understand how the underscores here are used
I know they can be used for "dumping" return values, but it's used differently here ..
The first underscore seems superfluous, since it's situated at the end
The second almost looks like a ternary condition to me, but I'm not really sure
Can someone please explain what the second underscore does?local r, _ = GetNumRaidMembers() > 0 and "raid" or "party"
for i = 1, 40 do
_ = UnitIsUnit("target",r..i.."target") and SendChatMessage("Hey, you're targeting the same unit as I am!", "WHISPER", nil, UnitName(r..i))
It might because Lua doesn't properly evaluate boolean conditions for the purposes of a short circuit of execution outside of an assignment statement. We don't care about the return value of UnitIsUnit or SendChatMessage in terms of persisting it, all we want to do is only SCM when UIU returns true. That said, another way to write that which doesn't use
many more characters and is somewhat more readable is...
if UnitIsUnit(...) then SendChatMessage(...) end
thanks for the explanationWe don't care about the return value of UnitIsUnitI really thought that the return value was actually important here. Seems I was wrong :)
These "boolean conditions for the purposes of a short circuit of execution outside of an assignment statement" are quite new to me
-- Is there any documentary on these "boolean conditions"? Like for
Yeah, it's almost exactly like the C-style ternary if...
<statement> ? <statement> : <statement>
It has some odd quirks in Lua though as it's not *really* a ternary if. The one used in the other macro wasn't even the full thing, it was just using the short circuiting of the and operator. Something like...
bool trash = Method1() && Method2();
Assuming both return bool, if 1 returns false, 2 won't be executed. In C# you can't use the && operator without it being an assignment or a conditional evaluation, but in C++ you might be able to shorthand it to just implicitly discard the value of the boolean evaluation. I know in C++ you can also implicitly use stuff as boolean that isn't.
However, using and+or for a fake ternary if is...
...as you linked. In both the case in this macro and in the and+or ternary, it's just using the short-circuiting of the boolean operators combined.
You are not logged in. Please
to post a reply or
if you don't already have an account.