Macros: Vanilla WoW LUA tips, chat & raid macros

Return to parent page for addons or more wow stuff

Here are some LUA programming examples and tips that are helpful when testing your macros or addons 🙂

Last updated: 2016-09-05

/run and /script are interchangeable so if you want more characters (max 255) use /run

Chat/messages

Print a string of your current target to chat log

/run DEFAULT_CHAT_FRAME:AddMessage("Hello world! my target name is "..GetUnitName("target"))

If your current target is a player then send a chat whisper to him/her

/run if UnitExists("target") then SendChatMessage("This is a test but insert whatever you are casting here","WHISPER",nil,UnitName("target")) end

The following will send your current location into PARTY chat:

/run local x,y=GetPlayerMapPosition("player") SendChatMessage("I'm at "..GetZoneText().." - "..GetMinimapZoneText().." - "..math.floor((x*100)+0,5).." "..math.floor((y*100)+0,5),"PARTY")

The following will do the same into BATTLEGROUND chat:

/run local x,y=GetPlayerMapPosition("player") SendChatMessage("I'm at "..GetZoneText().." - "..GetMinimapZoneText().." - "..math.floor((x*100)+0,5).." "..math.floor((y*100)+0,5),"BATTLEGROUND")

Unit info

Check if a unit is dead or ghost. Returns nil if alive and 1 if dead.

/run DEFAULT_CHAT_FRAME:AddMessage(tostring(UnitIsDeadOrGhost("target")))

Buffs/debuffs

Buffs in vanilla use interface names from the icon they have. That means you use the names of the icons to check instead of the actual buff name. Any more advanced checking wont fit inside a single macro. This is fairly confusing so in order to get the icon name you need to figure it out first.

List all icon names of buffs of your target.

/run for i=1,40 do if UnitBuff("target",i) then DEFAULT_CHAT_FRAME:AddMessage(tostring(i.."="..UnitBuff("target",i)),0.4,1,1) end end

List all icon names of debuffs of your target.

/run for i=1,40 do if UnitDebuff("target",i) then DEFAULT_CHAT_FRAME:AddMessage(tostring(i.."="..UnitDebuff("target",i)),0.4,1,1) end end

Check if a target has a certain buff icon name

/run for i=1,40 do if(strfind(tostring(UnitBuff("target",i)),"MyBuffName")) then c="Yes" end end if not c="Yes" then c="No" end DEFAULT_CHAT_FRAME:AddMessage(c)

Check if a target has a certain debuff icon name

/run for i=1,40 do if(strfind(tostring(UnitDebuff("target",i)),"MyBuffName")) then c="Yes" end end if not c="Yes" then c="No" end DEFAULT_CHAT_FRAME:AddMessage(c)

Raid buffs/debuffs

Combining the above we can do a for loop to check all the players in the raid for a specific debuff. In this example the Brood Affliction: Bronze from the boss Chromaggus in Blackwing Lair. After this boss theres usually a delay of trading Hourglass sand to get rid of the debuff. This macro will list all players in chat who has it.

/run b="n_Bronze" n="" r="raid" for i=1,GetNumRaidMembers()do for j=1,40 do if(strfind(tostring(UnitDebuff(r..i,j)),b))then n=UnitName(r..i)..", "..n break end end end if n==""then else SendChatMessage("Players with bronze debuff: "..n,"SAY",nil)end

The following is similar to above but will whisper to each player instead. Depending on server spam protection, this might not work.

/run b="n_Bronze" r="raid"for i=1,GetNumRaidMembers()do for j=1,40 do if(strfind(tostring(UnitDebuff(r..i,j)),b))then SendChatMessage("You've got Bronze debuff from Chromaggus use a Hourglass Sand.","WHISPER",nil,UnitName(r..i))break end end end

potion_fireThe following will instead check for players lacking a certain buff using a tiny function. In this example we’re checking for players who have NOT popped Fire Protection Potions and list them in chat. Remember that this conflicts with the warlock Imp fire resistance buff.

/run n=""r="raid"function b(k,l)for i=1,32 do if strfind(tostring(UnitBuff(r..l,i)),k)then return 1 end end end for l=1,GetNumRaidMembers() do if not b("e_FireA",l)then n=UnitName(r..l)..","..n end end SendChatMessage("Pop Fire pot:"..n,"SAY",nil)

Whisper each player lacking Fire Protection Potion instead:

/run n=""r="raid"function b(k,l)for i=1,32 do if strfind(tostring(UnitBuff(r..l,i)),k)then return 1 end end end for l=1,GetNumRaidMembers() do if not b("e_FireA",l)then SendChatMessage("Pop Fire prot potion!","WHISPER",nil,UnitName(r..l)) end end

potion_natureList players lacking Nature Protection Potion:

/run n=""r="raid"function b(k,l)for i=1,32 do if strfind(tostring(UnitBuff(r..l,i)),k)then return 1 end end end for l=1,GetNumRaidMembers() do if not b("e_SpiritA",l)then n=UnitName(r..l)..","..n end end SendChatMessage("Pop Nature pot:"..n,"SAY",nil)

Whisper each player lacking Nature Protection Potion:

/run n=""r="raid"function b(k,l)for i=1,32 do if strfind(tostring(UnitBuff(r..l,i)),k)then return 1 end end end for l=1,GetNumRaidMembers() do if not b("e_SpiritA",l)then SendChatMessage("Pop Nature prot potion!","WHISPER",nil,UnitName(r..l)) end end

potion_shadowList players lacking Shadow Protection Potion:

/run n=""r="raid"function b(k,l)for i=1,32 do if strfind(tostring(UnitBuff(r..l,i)),k)then return 1 end end end for l=1,GetNumRaidMembers() do if not b("w_RagingSc",l)then n=UnitName(r..l)..","..n end end SendChatMessage("Pop Shadow pot:"..n,"SAY",nil)

Whisper each player lacking Shadow Protection Potion:

/run n=""r="raid"function b(k,l)for i=1,32 do if strfind(tostring(UnitBuff(r..l,i)),k)then return 1 end end end for l=1,GetNumRaidMembers() do if not b("w_RagingSc",l)then SendChatMessage("Pop Shadow prot potion!","WHISPER",nil,UnitName(r..l)) end end

Raid

Go through the whole raid list and demote and kick every player character that is offline.

/run for i=1,GetNumRaidMembers() do u="raid"..i n=UnitName(u)if not UnitIsConnected(u) then DemoteAssistant(n)UninviteByName(n)end end

Similar to the above but will promote every player character that is online.

/run for i=1,GetNumRaidMembers() do u="raid"..i n=UnitName(u)if UnitIsConnected(u) then PromoteToAssistant(n)end end

 

Frames

To retrieve the name of the interface/addon frame you currently have your mousecursor hovered over

/run DEFAULT_CHAT_FRAME:AddMessage(GetMouseFocus():GetName())


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s