This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Live
PTR
10.2.7
PTR
10.2.6
Beta
[Macro] Whisper same target to warn of incoming CC
Post Reply
Return to board index
Post by
Fulgorater
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?
Post by
pelf
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
SendChatMessage(m,"WHISPER",nil,UnitName(ru))
end
end
elseif GetNumPartyMembers() then
for p=1,4 do
local pu = "party"..p
if UnitExists(pu) and UnitIsUnit("target",pu.."target") then
SendChatMessage(m,"WHISPER",nil,UnitName(pu))
end
end
end
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).
Post by
22686
This post was from a user who has deleted their account.
Post by
Fulgorater
Ah, thanks much you guys!
had a couple guildmates impressed by it and never got around to sharing it with them =D
Post by
pelf
Oh good call on condensing the loops. I guess an invalid unit just returns nil for UnitIsUnit. Very pro
:)
.
Post by
Onijitsu
That is the most elegant solution I've ever seen to one of the bigger (but more preventable) problems in dungeons and raids. Bravo!
Post by
Ketho
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))
end
Post by
pelf
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
that
many more characters and is somewhat more readable is...
if UnitIsUnit(...) then SendChatMessage(...) end
Post by
Ketho
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
ternary
operators
?
Post by
pelf
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...
http://lua-users.org/wiki/TernaryOperator
...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.
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.