Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active June 4, 2023 05:28
Show Gist options
  • Save cowboy/f75db2f760e3af31aebf39c101829eb6 to your computer and use it in GitHub Desktop.
Save cowboy/f75db2f760e3af31aebf39c101829eb6 to your computer and use it in GitHub Desktop.
WoW Classic :: CB_UpdateAssistMacro :: Update "/assist" line in a given macro to your current target
-- Copyright (c) 2019 "Cowboy" Ben Alman
-- Licensed under the MIT license
local function p(msg)
print("[CB_UpdateAssistMacro] " .. msg)
end
local function err(msg)
p("ERROR: " .. msg)
end
-- Helper functions from across the internet
local function split(s)
local words = {}
for word in s:gmatch("%S+") do table.insert(words, word) end
return words
end
local function shift(t)
return table.remove(t, 1)
end
local function map(array, fn)
local new_array = {}
for i, v in ipairs(array) do
new_array[i] = fn(v)
end
return new_array
end
local function map_over_lines(s, fn)
local lines = {}
for line in s:gmatch("[^\n]+") do table.insert(lines, line) end
lines = map(lines, fn)
return table.concat(lines, "\n")
end
local function starts_with(str, start)
return str:sub(1, #start) == start
end
-- Handle slash commands
SLASH_CB_UAM_MACRO1 = "/cb_uam"
SlashCmdList["CB_UAM_MACRO"] = function(msg)
local args = split(msg)
cb_uam(unpack(args))
end
-- Update assist macro
function cb_uam(macroName)
local usage = "usage: /cb_uam <macroname>"
if not macroName then
err("macroname not specified")
err(usage)
return
end
local name, icon, body = GetMacroInfo(macroName)
if not name then
err("macro " .. macroName .. " not found")
err(usage)
return
end
local target = UnitName("target")
if target then
p("Updating macro " .. macroName .. " to assist " .. target)
else
p("Updating macro " .. macroName .. " to NOT assist")
end
body = map_over_lines(body, function(line)
if starts_with(line, "/assist") or starts_with(line, "--/assist") then
if target then
return "/assist [noharm][dead] " .. target
else
return "--/assist"
end
else
return line
end
end)
EditMacro(macroName, macroName, nil, body)
end
p("loaded!")
## Interface: 11302
## Title: CB_UpdateAssistMacro
## Notes: Update "/assist" line in a given macro to your current target
## Author: Cowboy
## Version: v0.0.1
CB_UpdateAssistMacro.lua
@cowboy
Copy link
Author

cowboy commented Oct 10, 2019

  1. Create World of Warcraft\_classic_\Interface\Addons\CB_UpdateAssistMacro folder and put these files in there
  2. Start WoW Classic
  3. Add --/assist line to a macro where you'd want to do /assist [noharm][dead] someperson and note the macro's name
  4. Create another macro that runs /cb_uam the_other_macro_name
  5. Target a player (or nobody)
  6. Run the macro created in step 4 (out of combat)
  7. Murder

Notes:

  • What /assist [noharm][dead] someperson does: If you have no target, your current target is non-harmful ([noharm], ie. friendly or neutral) or your current target is dead ([nodead]) then assist someperson (set your target to be someperson's target).
  • For reference: Macro commands and Macro conditionals. Note that some of these might not work in WoW Classic.
  • Any line in a macro starting with -- will be ignored (-- is the Lua line comment marker)
  • Feel free to modify this macro to use your own slash command. If you do, tell me about it in the comments!

Eg.

"Initiate" macro

#showtooltip
--/assist
/target [@mouseover,harm,nodead][@target,harm,nodead][@pettarget]
/stopmacro [noharm][dead]
/dismount
/cast !Auto Shot
/cast Hunter's Mark
/petfollow
/petattack

"Set Assist" macro

/cb_uam Initiate

(The --/assist line will by dynamically updated when /cb_uam Initiate is run)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment