Im splitting the macro code up over multiple lines so its easier to understand what each part does

If you want the macro to work, you'll need to remove the unnecessary whitespace and line breaks.
First macro:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
|
/run -- execute the following lua code
for i=1,100 do -- iterate over all numbers from 1 to 100 in steps of 1
-- (so repeat the following block of commands for i=1, i=2, i=3, ..., i=100)
n,_,_,id=UnitBuff("player",i) -- get the name (n) and the id of the i-th buff of the player (you)
if id==500675 then -- if the id is equal to the one of a specific buff (stealth I guess)...
CancelPlayerBuff(i) -- then remove the buff...
break -- and stop iterating (break means you'll abort the for-loop
-- since we have found the stealth buff there's no need to look further
else -- if id is not equal...
CastSpellByName("Hide") -- try to cast hide
end
end
|
There is some weirdness going on in that macro: the variable n isn't used (anymore? i guess the check for the id qas originally a check for the buff name

), and it tries to cast hide
each iteration of the loop!! CastSpellByName is
not instant, it has a delay until the cast is executed, so even if the steatlh debuff was found and removed, hide would be cast regardless of that (unless the stealth buff was the first buff). Also, funnily, if CastSpellByName would be instant then it would remove the stealth buff you just got
a slightly better version of the same macro would look like this:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
/run
local wasHidden = false
for i=1,100 do
local _, _, _, id = UnitBuff("player", i)
if id == 500675 then
CancelPlayerBuff(i)
wasHidden = true
break
end
end
if not wasHidden then
CastSpellByName("Hide")
end
|
or that for short:
|
Source code
|
1
|
/run local w=0 for i=1,100 do local _,_,_,d=UnitBuff("player",i) if d==500675 then CancelPlayerBuff(i) w=1 break end end if w==0 then CastSpellByName("Hide") end
|
The better version only tries to cast Hide if there is no stealth buff found and after the loop is done so there is no way to mess it up
Second Macro:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
|
/run
hide = false;
for i=1,40 do
if UnitBuff("player",i) == "Hide" then
hide == "true"; -- error: should be hide = true
CancelPlayerBuff(i);
break
end
end
if hide == false then
CastSpellByName("Hide")
end
|
This macro looks quite familiar, doesn't it?

The main difference is that it's checking if the name matches instead of the id. But due to the line I commented the macro will throw an error, since it's trying to compare hide with "true" instead of assigning something to hide. Other than that, the stealth buff could be named differently than "Hide" (I'm playing on the german version, so I don't really know the exact english names

), which would make the macro fail to find the stealth buff and cast Hide anyways...
If something is not clear feel free to ask
EDIT: Lol, Uure was faster

I blame my registration process to the forum

To the semicolons: Lua treats them mostly like they aren't there, unless there would be some ambiguity whitout them like
|
Source code
|
1
2
|
func1(x)
(y and func2 or func3)(z)
|