From 649586c552caf8be8fd7ba5fe9678845f90d9d0a Mon Sep 17 00:00:00 2001 From: Jrc13245 Date: Thu, 15 Jan 2026 14:50:55 -0500 Subject: [PATCH] fix stopmacro and implement skipmacro --- Compatibility/SuperMacro.lua | 10 +++-- Console.lua | 7 +++- Core.lua | 78 ++++++++++++++++++++++++++++-------- README.md | 3 +- 4 files changed, 76 insertions(+), 22 deletions(-) diff --git a/Compatibility/SuperMacro.lua b/Compatibility/SuperMacro.lua index 95818ef..6e285cd 100644 --- a/Compatibility/SuperMacro.lua +++ b/Compatibility/SuperMacro.lua @@ -62,8 +62,8 @@ do CRM.Hooks.RunLine = CRM.Hooks.RunLine or orig_RunLine _G.RunLine = function(...) - -- Check stopmacro flag before processing any line - if CRM.stopMacroFlag then + -- Check macro stop flags before processing any line + if CRM.stopMacroFlag or CRM.skipMacroFlag then return true -- Skip this line, tell SM we handled it end @@ -126,8 +126,9 @@ do CRM.Hooks.SuperMacro_RunMacro = orig_SuperMacro_RunMacro local function hooked_RunMacro(index) - -- Clear stopmacro flag at macro start + -- Clear macro stop flags at macro start CRM.stopMacroFlag = false + CRM.skipMacroFlag = false return orig_SuperMacro_RunMacro(index) end @@ -143,8 +144,9 @@ do CRM.Hooks.RunSuperMacro = orig_RunSuperMacro _G.RunSuperMacro = function(index) - -- Clear stopmacro flag at macro start + -- Clear macro stop flags at macro start CRM.stopMacroFlag = false + CRM.skipMacroFlag = false return orig_RunSuperMacro(index) end end diff --git a/Console.lua b/Console.lua index 8f7a84d..d146b77 100644 --- a/Console.lua +++ b/Console.lua @@ -190,7 +190,7 @@ end -- /cast hook CleveRoids.Hooks.CAST_SlashCmd = SlashCmdList.CAST SlashCmdList.CAST = function(msg) - if CleveRoids.stopMacroFlag then return end + if CleveRoids.stopMacroFlag or CleveRoids.skipMacroFlag then return end if msg and string.find(msg, "[%[%?!~{]") then CleveRoids.DoCast(msg) else @@ -324,6 +324,11 @@ SlashCmdList.STOPMACRO = function(msg) CleveRoids.DoStopMacro(msg) end +SLASH_SKIPMACRO1 = "/skipmacro" +SlashCmdList.SKIPMACRO = function(msg) + CleveRoids.DoSkipMacro(msg) +end + -- QuickHeal with conditionals support (requires QuickHeal addon) -- Usage: /quickheal [conditionals] [target] [type] -- Examples: diff --git a/Core.lua b/Core.lua index 8396269..107597d 100644 --- a/Core.lua +++ b/Core.lua @@ -1256,22 +1256,35 @@ end -- Executes the given Macro's body -- body: The Macro's body +-- Note on macro flags: +-- stopMacroFlag: Stops ALL remaining lines (propagates to parent macros) +-- skipMacroFlag: Stops only current macro (cleared on return, parent continues) function CleveRoids.ExecuteMacroBody(body,inline) local lines = CleveRoids.splitString(body, "\n") if inline then lines = CleveRoids.splitString(body, "\\n"); end - -- Clear stopmacro flag at start of macro execution - CleveRoids.stopMacroFlag = false + -- Save parent's stopMacroFlag state (in case we need to preserve it) + local parentStopFlag = CleveRoids.stopMacroFlag + + -- Clear flags at start of this macro execution + -- Note: We DON'T clear if parent already set stopMacroFlag (shouldn't execute at all) + if not parentStopFlag then + CleveRoids.stopMacroFlag = false + end + CleveRoids.skipMacroFlag = false -- Always start fresh for skipmacro if CleveRoids.macroRefDebug then CleveRoids.Print("|cff00ffff[MacroRef]|r ExecuteMacroBody called with " .. table.getn(lines) .. " lines") end for k,v in pairs(lines) do - -- Check stopmacro flag before each line - if CleveRoids.stopMacroFlag then + -- Check both macro stop flags before each line + -- stopMacroFlag: stop this AND parent macros + -- skipMacroFlag: stop only this macro (parent continues) + if CleveRoids.stopMacroFlag or CleveRoids.skipMacroFlag then if CleveRoids.macroRefDebug then - CleveRoids.Print("|cffff8800[MacroRef]|r Stopped at line " .. k .. " due to /stopmacro") + local reason = CleveRoids.stopMacroFlag and "/stopmacro" or "/skipmacro" + CleveRoids.Print("|cffff8800[MacroRef]|r Stopped at line " .. k .. " due to " .. reason) end break end @@ -1281,6 +1294,11 @@ function CleveRoids.ExecuteMacroBody(body,inline) ChatFrameEditBox:SetText(v) ChatEdit_SendText(ChatFrameEditBox) end + + -- Clear skipMacroFlag after this macro completes (don't propagate to parent) + -- stopMacroFlag is intentionally LEFT SET so it propagates up + CleveRoids.skipMacroFlag = false + return true end @@ -2075,9 +2093,9 @@ function CleveRoids.TestAction(cmd, args) end function CleveRoids.DoWithConditionals(msg, hook, fixEmptyTargetFunc, targetBeforeAction, action) - -- Check stopmacro flag (skip non-STOPMACRO commands when flag is set) - -- This enables /stopmacro to work without SuperMacro for vanilla macros - if CleveRoids.stopMacroFlag and action ~= "STOPMACRO" then + -- Check macro stop flags (skip non-STOPMACRO/SKIPMACRO commands when flag is set) + -- This enables /stopmacro and /skipmacro to work without SuperMacro for vanilla macros + if (CleveRoids.stopMacroFlag or CleveRoids.skipMacroFlag) and action ~= "STOPMACRO" and action ~= "SKIPMACRO" then return false end @@ -2101,6 +2119,15 @@ function CleveRoids.DoWithConditionals(msg, hook, fixEmptyTargetFunc, targetBefo end end + -- Handle STOPMACRO/SKIPMACRO without conditionals (bare command) + if action == "STOPMACRO" then + CleveRoids.stopMacroFlag = true + return true + elseif action == "SKIPMACRO" then + CleveRoids.skipMacroFlag = true + return true + end + if hook then hook(msg) end @@ -2217,9 +2244,13 @@ function CleveRoids.DoWithConditionals(msg, hook, fixEmptyTargetFunc, targetBefo end if action == "STOPMACRO" then - -- Set flag to stop subsequent lines in current macro + -- Set flag to stop subsequent lines in current macro AND parent macros CleveRoids.stopMacroFlag = true return true + elseif action == "SKIPMACRO" then + -- Set flag to skip remaining lines in current submacro only + CleveRoids.skipMacroFlag = true + return true end local result = true @@ -2321,8 +2352,8 @@ function CleveRoids.DoCastPet(msg) end function CleveRoids.DoTarget(msg) - -- Check stopmacro flag - if CleveRoids.stopMacroFlag then + -- Check macro stop flags + if CleveRoids.stopMacroFlag or CleveRoids.skipMacroFlag then return false end @@ -2622,8 +2653,8 @@ end -- Also checks if a condition is a spell so that you can mix item and spell use -- msg: The raw message intercepted from a /use or /equip command function CleveRoids.DoUse(msg) - -- Check stopmacro flag - if CleveRoids.stopMacroFlag then + -- Check macro stop flags + if CleveRoids.stopMacroFlag or CleveRoids.skipMacroFlag then return false end @@ -3201,7 +3232,7 @@ function CleveRoids.DoRetarget() end end --- Attempts to stop macro +-- Attempts to stop macro (stops ALL remaining lines including parent macros) function CleveRoids.DoStopMacro(msg) -- PERFORMANCE: Use numeric iteration to avoid pairs() iterator allocation local parts = CleveRoids.splitStringIgnoringQuotes(CleveRoids.Trim(msg)) @@ -3213,6 +3244,18 @@ function CleveRoids.DoStopMacro(msg) return false end +-- Attempts to skip remaining lines in current submacro ONLY (returns to parent) +function CleveRoids.DoSkipMacro(msg) + -- PERFORMANCE: Use numeric iteration to avoid pairs() iterator allocation + local parts = CleveRoids.splitStringIgnoringQuotes(CleveRoids.Trim(msg)) + for i = 1, table.getn(parts) do + if CleveRoids.DoWithConditionals(msg, nil, nil, not CleveRoids.hasSuperwow, "SKIPMACRO") then + return true + end + end + return false +end + function CleveRoids.DoCastSequence(sequence) if not CleveRoids.hasSuperwow then CleveRoids.Print("|cFFFF0000/castsequence|r requires |cFF00FFFFSuperWoW|r.") @@ -3320,12 +3363,15 @@ local UnitAffectingCombat = UnitAffectingCombat local pairs = pairs function CleveRoids.OnUpdate(self) - -- Clear stopmacro flag at the start of each frame - -- This ensures /stopmacro only affects commands in the same frame (same macro execution) + -- Clear macro stop flags at the start of each frame + -- This ensures /stopmacro and /skipmacro only affect commands in the same frame (same macro execution) -- Without SuperMacro, this is necessary because we can't hook into macro line execution if CleveRoids.stopMacroFlag then CleveRoids.stopMacroFlag = false end + if CleveRoids.skipMacroFlag then + CleveRoids.skipMacroFlag = false + end -- PERFORMANCE: Single GetTime() call per frame local time = GetTime() diff --git a/README.md b/README.md index cb4a619..e6c1bbc 100644 --- a/README.md +++ b/README.md @@ -320,7 +320,8 @@ These commands accept `[conditionals]` and use UnitXP 3D enemy scanning when app | `/cleartarget [cond]` | ✅ | — | Clear target if conditions met | | `/cancelaura [cond] Name` | ✅ | — | Cancel buff if conditions met | | `/quickheal [cond]` | ✅ | — | Smart heal (requires QuickHeal) | -| `/stopmacro [cond]` | ✅ | — | Stop macro execution if conditions met | +| `/stopmacro [cond]` | ✅ | — | Stop ALL macro execution (including parent macros) | +| `/skipmacro [cond]` | ✅ | — | Stop current submacro only, parent continues | | `/petattack [cond]` | ✅ | — | Pet attack with conditionals | | `/petfollow [cond]` | ✅ | — | Pet follow with conditionals | | `/petwait [cond]` | ✅ | — | Pet stay with conditionals |