From d825c3536c39fdea4f6000b0e70c2b7ac1c5bd60 Mon Sep 17 00:00:00 2001 From: Jrc13245 Date: Mon, 26 Jan 2026 15:20:38 -0500 Subject: [PATCH] make non monkeyspeed users as fast as monkeyspeed for moving --- Conditionals.lua | 29 ++++++++++++++++++++++++----- Core.lua | 29 +++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/Conditionals.lua b/Conditionals.lua index a58faa5..6ad8172 100644 --- a/Conditionals.lua +++ b/Conditionals.lua @@ -2171,9 +2171,29 @@ function CleveRoids.IsPlayerMoving() return (MonkeySpeed.m_fSpeed or 0) > 0 end - -- Fallback: use continuously tracked position data from OnUpdate - -- Core.lua tracks position at ~10 Hz, storing _currentPlayerPos and _previousPlayerPos - -- This is more accurate than the old method which only updated on macro execution + -- Fallback: use continuously tracked position history from OnUpdate + -- Core.lua tracks position at ~100 Hz with 4-sample history (matches MonkeySpeed's 0.01s). + -- Movement is detected if ANY consecutive pair of samples shows movement. + -- This gives instant start-of-movement detection (first sample shows delta). + local history = CleveRoids._positionHistory + + if history and table.getn(history) >= 2 then + -- Check all consecutive pairs in history - moving if ANY shows movement + -- This detects start-of-movement immediately when first delta appears + for i = 2, table.getn(history) do + local prev = history[i - 1] + local curr = history[i] + local dx = curr.x - prev.x + local dy = curr.y - prev.y + local dist = math.sqrt(dx * dx + dy * dy) + if dist > 0.001 then + return true -- Any movement in recent history = moving + end + end + return false -- No movement in any recent sample = stopped + end + + -- Legacy fallback for code that might not have history yet local current = CleveRoids._currentPlayerPos local previous = CleveRoids._previousPlayerPos @@ -2181,11 +2201,10 @@ function CleveRoids.IsPlayerMoving() local dx = current.x - previous.x local dy = current.y - previous.y local dist = math.sqrt(dx * dx + dy * dy) - -- Moving if distance > small threshold (account for floating point) return dist > 0.001 end - -- Not enough data yet (first 0.2s after login) - assume not moving + -- Not enough data yet (first 0.15s after login) - assume not moving return false end diff --git a/Core.lua b/Core.lua index 965528a..5548e78 100644 --- a/Core.lua +++ b/Core.lua @@ -3576,10 +3576,11 @@ function CleveRoids.OnUpdate(self) -- ========================================================================= -- CONTINUOUS POSITION TRACKING (for [moving] fallback without MonkeySpeed) -- ========================================================================= - -- Track player position at ~10 Hz for accurate movement detection. - -- This runs every frame but only updates storage at the tracking interval. + -- Track player position at ~100 Hz with 4-sample history for snappy movement detection. + -- Matches MonkeySpeed's 0.01s detection interval for similar responsiveness. + -- This provides instant start-of-movement detection and quick stop detection. -- Without this, [moving] only updates when macros execute (stale data). - local posTrackInterval = 0.1 -- 100ms between position samples + local posTrackInterval = 0.01 -- 10ms between position samples (100 Hz, matches MonkeySpeed) local lastPosTime = CleveRoids._positionTrackTime or 0 if (time - lastPosTime) >= posTrackInterval then @@ -3588,9 +3589,25 @@ function CleveRoids.OnUpdate(self) if UnitPosition then local x, y = UnitPosition("player") if x and y then - -- Shift current to previous, store new current - CleveRoids._previousPlayerPos = CleveRoids._currentPlayerPos - CleveRoids._currentPlayerPos = { x = x, y = y, time = time } + -- Initialize history buffer if needed + if not CleveRoids._positionHistory then + CleveRoids._positionHistory = {} + end + + -- Add new sample to history + local history = CleveRoids._positionHistory + table.insert(history, { x = x, y = y, time = time }) + + -- Keep only last 4 samples (40ms window at 10ms intervals) + while table.getn(history) > 4 do + table.remove(history, 1) + end + + -- Also maintain legacy vars for any code that uses them directly + if table.getn(history) >= 2 then + CleveRoids._previousPlayerPos = history[table.getn(history) - 1] + CleveRoids._currentPlayerPos = history[table.getn(history)] + end end end end