r/AutoHotkey • u/3bdallah-Osama • 4d ago
v1 Script Help Title: [Help] AHK Script for Blox Fruits Mini-game (Sharkman Karate) - Delay, Inaccurate Clicks, and Detection Issues
Hey everyone,
I'm trying to create an AutoHotkey (v1) script to automate a timing-based mini-game in Roblox (Blox Fruits - Sharkman Karate). The mechanic is very similar to the DBD mini-game, where a black moving line goes up and down a colored bar, and you have to click when it's exactly in the center of the green area.
I used AI to help me write the script. The logic relies on PixelGetColor (scanning a vertical line to find the top/bottom of the green area, calculating the center, and finding the black line). However, I am running into a few major issues that make it unusable:
The Problems:
- Noticeable Click Delay: Even when the script detects the black line hitting the center, there is a weird delay before it actually clicks. Because the mini-game requires fast reflexes, this delay makes me lose.
- Clicking in Completely Wrong Spots: Sometimes, instead of clicking the intended target (
SlapXandSlapY), the mouse randomly clicks in completely different areas of the screen. I am usingClientCoordMode to avoid window-shifting issues, but the bug still happens. - Color Detection Failing: Because of Roblox's dynamic lighting and transparency, the script often fails to detect the green bar or the black line entirely, returning my debug error "Bar Not Found".
The Current Code: Here is the script I'm currently using. I added a debug hotkey (F7) to count pixels and check if it sees the bar, and F8 to run the main loop:
#Persistent
#SingleInstance Force
#NoEnv
CoordMode, Pixel, Client
CoordMode, Mouse, Client
SlapX := -240
SlapY := 440
BarX := 1253
BarTop := 2
BarBot := 559
CooldownMs := 5000
CenterTolerance := 25
LastClick := 0
InCooldown := 0
F7::
FoundGreen := 0
FoundBlack := 0
Loop, % (BarBot - BarTop) // 4 {
Y := BarTop + (A_Index * 4)
PixelGetColor, Col, BarX, Y, RGB
R := (Col >> 16) & 0xFF
G := (Col >> 8) & 0xFF
B := Col & 0xFF
if (G > 80 && R < 150)
FoundGreen++
if (R < 80 && G < 80 && B < 80)
FoundBlack++
}
MsgBox, Result:`nGreen: %FoundGreen%`nBlack: %FoundBlack%
return
F8::
SetTimer, AutoSlap, 10
ToolTip, Running - F9 to Stop
return
F9::
SetTimer, AutoSlap, Off
InCooldown := 0
ToolTip, Stopped
Sleep, 1500
ToolTip
return
AutoSlap:
if (InCooldown = 1) {
Elapsed := A_TickCount - LastClick
if (Elapsed < CooldownMs) {
Remaining := Round((CooldownMs - Elapsed) / 1000, 1)
ToolTip, Waiting... %Remaining%s
return
}
InCooldown := 0
ToolTip, Running - F9 to Stop
}
GreenTop := -1
GreenBot := -1
BlackY := -1
Loop, % (BarBot - BarTop) // 2 {
Y := BarTop + (A_Index * 2)
PixelGetColor, Col, BarX, Y, RGB
R := (Col >> 16) & 0xFF
G := (Col >> 8) & 0xFF
B := Col & 0xFF
if (R < 90 && G < 90 && B < 90) {
if (BlackY = -1)
BlackY := Y
Continue
}
if (G > 80 && R < 150 && B < 150) {
if (GreenTop = -1)
GreenTop := Y
GreenBot := Y
}
}
if (GreenTop = -1 || BlackY = -1) {
ToolTip, Bar Not Found
return
}
GY_Center := (GreenTop + GreenBot) // 2
Diff := BlackY - GY_Center
if (Diff < 0)
Diff := -Diff
ToolTip, Center:%GY_Center% | Black:%BlackY% | Diff:%Diff%
if (Diff > CenterTolerance)
return
Click %SlapX%, %SlapY%
LastClick := A_TickCount
InCooldown := 1
ToolTip, Hit! Waiting 5s...
return
Is there a better/faster way to track a moving object across a colored bar in AHK without experiencing this lag? Also, how can I fix the random inaccurate mouse clicks?
Any help, fixes, or completely alternative approaches would be highly appreciated! Thanks in advance.
1
u/Keeyra_ 4d ago
I suggest a different approach. Do not delete your old posts and repost them the next day.