Morkah, my dude, thanks for the addon.
I watered down your code into this:
Code: Select all
-- StartAutoAttack - Vanilla 1.12.1 / Lua 5.0
--
-- Adds two slash commands:
-- /start_auto_attack - begins auto-attack on your current target, if possible
-- /stop_auto_attack - stops auto-attack, if currently active
--
-- Intended usage is inside your own ability macros, e.g.:
--
-- /start_auto_attack
-- /cast Judgement(Rank 3)
--
-- /stop_auto_attack
-- /cast Intimidating Shout
--
-- Requires "Attack" (from your spellbook's "General" tab) to be placed somewhere
-- in your action bars. Anywhere on the bars is fine, any page, can be hidden/unused.
local attackActionSlot = 1
local function GetAttackActionSlot()
local slot = attackActionSlot
if IsAttackAction(slot) then
return slot
end
slot = 1
while slot <= 120 do
if IsAttackAction(slot) then
attackActionSlot = slot
return slot
end
slot = slot + 1
end
DEFAULT_CHAT_FRAME:AddMessage("|cffff3333StartAutoAttack:|r Please place the 'Attack' action (from the 'General' tab of your spellbook) anywhere on your action bars. This addon can not function without it.")
return nil
end
local function GetAttackStatus()
local slot = GetAttackActionSlot()
if not slot then
return nil
end
if IsCurrentAction(slot) then
return "on";
else
return "off";
end
end
local function StartAutoAttack()
if GetAttackStatus() == "off" then
if UnitExists("target") and not UnitIsDead("target") and UnitCanAttack("player", "target") then
AttackTarget()
end
end
end
local function StopAutoAttack()
if GetAttackStatus() == "on" then
AttackTarget()
end
end
SLASH_STARTAUTOATTACK1 = "/start_auto_attack"
SlashCmdList["STARTAUTOATTACK"] = function()
StartAutoAttack()
end
SLASH_STOPAUTOATTACK1 = "/stop_auto_attack"
SlashCmdList["STOPAUTOATTACK"] = function()
StopAutoAttack()
end
Lets me put /start_auto_attack and /stop_auto_attack into the macros for the keybinds I mash on a new target. For me this is enough (same as /startattack and /stopattack in newer versions of the game). If you wanna publish it go ahead as it's mostly your work.
My changes: This *requires* that "Attack" be somewhere on the action bars. No enable/disable, does not track in/out of combat, does not keep an attackActive variable because it always gets the answer from the action bars, and caches the action bar slot number to save some CPU cycles.
SeniorMOO