Last active
June 4, 2023 05:28
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
World of Warcraft\_classic_\Interface\Addons\CB_UpdateAssistMacro
folder and put these files in there--/assist
line to a macro where you'd want to do/assist [noharm][dead] someperson
and note the macro's name/cb_uam the_other_macro_name
Notes:
/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).--
will be ignored (--
is the Lua line comment marker)Eg.
"Initiate" macro
"Set Assist" macro
(The
--/assist
line will by dynamically updated when/cb_uam Initiate
is run)