05-03-26
Progressive Recoil Control Lua Script
This Lua script for Rebind hardware input provides progressive recoil control, increasing recoil intensity over time while holding the fire button. Customize initial strength, peak strength, and ramp
Question
Progressive recoil curve over time
Rebind AI
-- rebind: min_sdk=0.1.0
-- rebind: name=Progressive Recoil Curve
-- rebind: description=Recoil increases over time while holding fire
local cfg = UI.Schema({
enabled = UI.Toggle(true, { label = "Enable" }),
initial_strength = UI.Slider(50, { min = 10, max = 200, suffix = "%", group = "Recoil" }),
peak_strength = UI.Slider(150, { min = 50, max = 300, suffix = "%", group = "Recoil" }),
ramp_time = UI.Slider(1000, { min = 200, max = 3000, suffix = "ms", label = "Time to Peak", group = "Recoil" }),
fire_rate = UI.Slider(10, { min = 1, max = 30, label = "Fire Rate", suffix = "cps", group = "Recoil" }),
})
-- Base recoil pattern (one cycle)
local pattern = {
{ x = 0, y = 2, delay = 10 },
{ x = -1, y = 3, delay = 10 },
{ x = 1, y = 3, delay = 10 },
{ x = 0, y = 2, delay = 10 },
}
local activeTask = nil
local function getStrengthAtTime(elapsed)
-- Linear ramp from initial to peak
local progress = math.min(elapsed / cfg.ramp_time, 1.0)
local strength = cfg.initial_strength + (cfg.peak_strength - cfg.initial_strength) * progress
return strength / 100
end
function OnDown(code)
if code == "Mouse1" and cfg.enabled then
activeTask = Run(function()
local holdStart = System.Time()
local cycleInterval = 1000 / cfg.fire_rate
while Input.IsDown("Mouse1") do
local elapsed = System.Time() - holdStart
local strength = getStrengthAtTime(elapsed)
local scaled = Math.Scale(pattern, strength, strength)
for _, step in ipairs(scaled) do
if not Input.IsDown("Mouse1") then break end
HID.Move(step.x, step.y)
Sleep(step.delay or 10)
end
Sleep(math.max(0, cycleInterval - 40))
end
end)
return false
end
end
function OnUp(code)
if code == "Mouse1" and activeTask then
activeTask:Cancel()
activeTask = nil
end
end
function OnBlur()
if activeTask then
activeTask:Cancel()
activeTask = nil
end
endHow it works:
The script applies a linear ramp from initial_strength to peak_strength over the duration specified in ramp_time. The longer you hold the mouse button, the stronger the recoil becomes.
- Initial Strength: Starting recoil intensity (%)
- Peak Strength: Maximum recoil intensity after ramping up (%)
- Ramp Time: How long it takes to go from initial to peak (ms)
- Fire Rate: How many recoil cycles per second
The getStrengthAtTime() function calculates what percentage of the ramp you're at based on elapsed time, then Math.Scale() applies that multiplier to the base pattern.
When you release the mouse button, the task cancels immediately. If you click again, the timer resets and begins a fresh ramp.
Learn more