Your first script
In five minutes you'll have a working aim-assist script with a tunable GUI slider. We'll build it line by line and explain what each part does.
Goal
A script that:
- Only acts when the model is confident about a detection
- Aims toward the target's center
- Scales the aim adjustment by a user-tunable strength slider
The script
//!gui:slider var=strength label="Aim Strength" min=0 max=1 default=0.5 step=0.05
if (confidence < 0.5) {
return (0, 0);
}
x = (detection.x - center_x) * settings.strength;
y = (detection.y - center_y) * settings.strength;
return (x, y);
That's the whole thing. Let's walk through it.
Line by line
Line 1 — the GUI directive
//!gui:slider var=strength label="Aim Strength" min=0 max=1 default=0.5 step=0.05
This special comment tells AimForge to create a slider in the GUI. The slider's value is bound to settings.strength. You can read it from anywhere in the script.
| Attribute | What it does |
|---|---|
var=strength |
The variable name (read as settings.strength). |
label="Aim Strength" |
The label shown next to the slider. |
min=0 max=1 |
The slider's range. |
default=0.5 |
The initial value. |
step=0.05 |
The slider snap increment. |
See GUI directives for the full list.
Lines 3–5 — the confidence guard
if (confidence < 0.5) {
return (0, 0);
}
confidence is a built-in variable — the model's confidence in the current detection (0 to 1). If it's below 0.5, we bail out early with return (0, 0) — no aim adjustment this frame.
This is important. Models sometimes detect ghosts (UI elements, distant teammates, environmental shapes). The confidence gate filters those out.
Lines 7–8 — the aim offset
x = (detection.x - center_x) * settings.strength;
y = (detection.y - center_y) * settings.strength;
detection.x and detection.y are the pixel coordinates of the detection's center. center_x and center_y are the screen center.
Subtracting gives us the offset from the crosshair to the target. Multiplying by settings.strength (a value between 0 and 1) scales that offset — so a strength of 0.5 means "move halfway toward the target" each frame.
Line 10 — the return
return (x, y);
Every script returns a tuple. The first value is the X output (positive = right), the second is Y (positive = down). The runtime sends these to the active input device.
Run it
Save the script to a .afp file, then load it from the AimForge script panel. The Strength slider will appear in the GUI — adjust it live to feel the difference.
What to try next
Things you can change to learn the system:
-
Change the confidence threshold. Try
0.7for stricter targeting,0.3for laxer. -
Add a deadzone. Skip output if
hypot(detection.x - center_x, detection.y - center_y) < 5— useful when the crosshair is already on target. - Add a second slider for a "max distance" filter — only aim at targets within N pixels.
- Add smoothing. Walk through the aim-assist example which adds exponential smoothing to feel less robotic.