05-03-26
Dynamic FOV Circle Tightener Script
This Lua script for hardware input dynamically tightens your aiming circle when aiming down sights and a target is detected. Configure the ADS key, FOV, target color, and more using the UI.
Question
Code me a script that tightens the fov circle when ads and detecting a target
Rebind AI
-- rebind: min_sdk=0.1.0
-- rebind: name=FOV Circle Tightener
-- rebind: description=Reduces mouse movement range when ADS with target detected
local cfg = UI.Schema({
enabled = UI.Toggle(true, { label = "Enable" }),
ads_key = UI.Keybind("RMB", { label = "ADS Key" }),
fov_normal = UI.Slider(100, {
min = 10,
max = 200,
suffix = "%",
label = "Normal FOV",
group = "FOV Settings",
}),
fov_ads = UI.Slider(50, {
min = 10,
max = 100,
suffix = "%",
label = "ADS FOV",
group = "FOV Settings",
}),
target_color = UI.Text("FF0000", {
label = "Target Color (Hex)",
placeholder = "FF0000",
maxLength = 6,
group = "Target Detection",
}),
color_tolerance = UI.Slider(30, {
min = 0,
max = 100,
label = "Color Tolerance",
group = "Target Detection",
}),
check_radius = UI.Slider(100, {
min = 20,
max = 300,
suffix = "px",
label = "Check Radius",
group = "Target Detection",
}),
})
local isADS = false
local targetDetected = false
local lastMoveDX = 0
local lastMoveDY = 0
local function hexToRgb(hex)
return tonumber(hex:sub(1, 2), 16), tonumber(hex:sub(3, 4), 16), tonumber(hex:sub(5, 6), 16)
end
local function colorDistance(hex1, hex2)
local r1, g1, b1 = hexToRgb(hex1)
local r2, g2, b2 = hexToRgb(hex2)
return math.sqrt((r2 - r1) ^ 2 + (g2 - g1) ^ 2 + (b2 - b1) ^ 2)
end
local function scanForTarget()
if not isADS then
return false
end
local w, h = System.Screen()
local centerX = math.floor(w / 2)
local centerY = math.floor(h / 2)
local radius = cfg.check_radius
-- Sample multiple points around center in a circle pattern
for angle = 0, 360, 45 do
local rad = math.rad(angle)
local x = centerX + math.floor(math.cos(rad) * radius)
local y = centerY + math.floor(math.sin(rad) * radius)
local pixel = Screen.GetPixelColor(x, y)
if colorDistance(pixel, cfg.target_color) <= cfg.color_tolerance then
return true
end
end
-- Also check center
local centerPixel = Screen.GetPixelColor(centerX, centerY)
if colorDistance(centerPixel, cfg.target_color) <= cfg.color_tolerance then
return true
end
return false
end
function OnDown(key)
if not cfg.enabled then
return true
end
if key == cfg.ads_key then
isADS = true
return true
end
return true
end
function OnUp(key)
if key == cfg.ads_key then
isADS = false
targetDetected = false
return true
end
return true
end
function OnMove(dx, dy)
if not cfg.enabled or not isADS then
return true
end
lastMoveDX = dx
lastMoveDY = dy
-- Scan for target
targetDetected = scanForTarget()
if not targetDetected then
return true
end
-- Apply FOV circle tightening
local fovFactor = cfg.fov_ads / 100
local tightenedDX = dx * fovFactor
local tightenedDY = dy * fovFactor
HID.Move(tightenedDX, tightenedDY)
return false
end
function OnTick()
-- Optional: provide visual feedback via logs (disable for performance if needed)
-- Uncomment to see real-time target detection
-- if isADS and targetDetected then
-- Log.Debug("Target locked!")
-- end
end
function OnBlur()
isADS = false
targetDetected = false
endHow It Works
This script implements dynamic FOV circle tightening that activates when you ADS (aim down sights) and a target is detected:
-
ADS Detection: Monitors your ADS key (default Right Mouse Button). When pressed, the script enters ADS mode.
-
Target Scanning: While ADS is active, continuously scans a circular area around your screen center for pixels matching your target color (default red
FF0000). -
FOV Restriction: When a target is detected, incoming mouse movement is scaled down by the ADS FOV percentage. For example, with 50% ADS FOV, a 100px movement becomes 50px, creating a tighter aiming circle.
-
Smart Sampling: The scan checks multiple points around the center plus the center itself to detect targets reliably without excessive CPU usage.
-
Cleanup: On blur (window loses focus), both ADS and target states reset to prevent stuck states.
UI Configuration
- Enable: Toggle the entire feature on/off
- ADS Key: Which key triggers aim mode (default RMB)
- Normal/ADS FOV: Movement scale percentages (100% = unchanged, 50% = half sensitivity)
- Target Color: Hex color of the reticle/target marker to detect
- Color Tolerance: How similar colors need to be to count as a match (higher = more forgiving)
- Check Radius: How far from screen center to search for targets (pixels)