I need help please,
My script starts well but closes each time I click on save and does not reuse the settings.ini. And above all, it does not search for the color on the screen.
Thank you all.
Code: Select all
#SingleInstance Force
CoordMode, Pixel, Screen
Gui, Add, Text, x10 y10 w150 h20, Welcome to the matrix
Gui, Add, Text, x10 y30 w150 h20, Screen resolution:
Gui, Add, Text, x10 y60 w150 h20, Width:
Gui, Add, Edit, x170 y60 w50 h20 vScreenWidth, 2560
Gui, Add, Text, x10 y90 w150 h20, Height:
Gui, Add, Edit, x170 y90 w50 h20 vScreenHeight, 1440
Gui, Add, Text, x10 y120 w150 h20, Color to search (RGB format):
Gui, Add, Edit, x10 y150 w100 h20 vPixelColor, FF0000
Gui, Add, Text, x10 y180 w150 h20, Color tolerance:
Gui, Add, Edit, x10 y210 w100 h20 vTolerance, 20
Gui, Add, Text, x10 y240 w150 h20, Search area:
Gui, Add, Text, x10 y270 w150 h20, Start X:
Gui, Add, Edit, x170 y270 w50 h20 vStartX, 0
Gui, Add, Text, x10 y300 w150 h20, Start Y:
Gui, Add, Edit, x170 y300 w50 h20 vStartY, 0
Gui, Add, Text, x10 y330 w150 h20, End X:
Gui, Add, Edit, x170 y330 w50 h20 vEndX, 50
Gui, Add, Text, x10 y360 w150 h20, End Y:
Gui, Add, Edit, x170 y360 w50 h20 vEndY, 50
Gui, Add, Text, x10 y390 w150 h20, Click type:
Gui, Add, Checkbox, x170 y390 w100 h20 vLeftClick, Left click
Gui, Add, Checkbox, x170 y420 w100 h20 vRightClick, Right click
Gui, Add, Button, x10 y450 w100 h30 gSaveSettings, Save
Gui, Add, Button, x120 y450 w100 h30 gStartScript, Start
Gui, Add, Text, x10 y480 w150 h20, Spelth
Gui, Show, w250 h520, Configuration settings
return
SaveSettings:
Gui, Submit
IniWrite, % ScreenWidth, Settings.ini, Config, ScreenWidth
IniWrite, % ScreenHeight, Settings.ini, Config, ScreenHeight
IniWrite, % PixelColor, Settings.ini, Config, PixelColor
IniWrite, % Tolerance, Settings.ini, Config, Tolerance
IniWrite, % StartX, Settings.ini, Config, StartX
IniWrite, % StartY, Settings.ini, Config, StartY
IniWrite, % EndX, Settings.ini, Config, EndX
IniWrite, % EndY, Settings.ini, Config, EndY
IniWrite, % LeftClick, Settings.ini, Config, LeftClick
IniWrite, % RightClick, Settings.ini, Config, RightClick
MsgBox, 64, Save, Settings have been saved successfully.
return
StartScript:
if !FileExist("Settings.ini")
{
MsgBox, 48, Error, Settings file not found. Please configure the settings first.
return
}
IniRead, ScreenWidth, Settings.ini, Config, ScreenWidth
IniRead, ScreenHeight, Settings.ini, Config, ScreenHeight
IniRead, PixelColor, Settings.ini, Config, PixelColor
IniRead, Tolerance, Settings.ini, Config, Tolerance
IniRead, StartX, Settings.ini, Config, StartX
IniRead, StartY, Settings.ini, Config, StartY
IniRead, EndX, Settings.ini, Config, EndX
IniRead, EndY, Settings.ini, Config, EndY
IniRead, LeftClick, Settings.ini, Config, LeftClick
IniRead, RightClick, Settings.ini, Config, RightClick
CrossColor := PixelColor
Width := EndX - StartX
Height := EndY - StartY
; Initialize pause state of the script
Paused := false
; Initialize variables for mouse movement
X_Start := 0
Y_Start := 0
Distance := 10 ; 1 cm on a 2k screen (2560 pixels wide)
MoveMouse := false
; Function to search for the enemy's head
SearchEnemyHead() {
X_Start := StartX
Y_Start := StartY
X_End := EndX
Y_End := EndY
Loop, % Width {
Loop, % Height {
PixelGetColor, PixelColor, % X_Start+A_Index-1, % Y_Start+A_Index-1
Difference := ColorDifference(CrossColor, PixelColor)
if (Difference <= Tolerance) {
X_Target := X_Start + (Width // 2)
Y_Target := Y_Start + (Height // 2)
MouseMove, % X_Target, % Y_Target
return
}
}
}
}
; Function for mouse movement
MoveMouse() {
MouseGetPos, X_Current, Y_Current
if (MoveMouse) {
New_X := X_Start + Distance
New_Y := Y_Start + Distance
MouseMove, % New_X, % New_Y
}
}
; Calculate color difference between two RGB colors
ColorDifference(Color1, Color2) {
R1 := (Color1 >> 16) & 0xFF, G1 := (Color1 >> 8) & 0xFF, B1 := Color1 & 0xFF
R2 := (Color2 >> 16) & 0xFF, G2 := (Color2 >> 8) & 0xFF, B2 := Color2 & 0xFF
return sqrt((R2 - R1) ** 2 + (G2 - G1) ** 2 + (B2 - B1) ** 2)
}
; Watch key to pause or resume the script
End::
Paused := !Paused
if (!Paused) {
SoundBeep, 500, 100
}
return
; Loop to continuously monitor left mouse button click
While (true) {
if (Paused)
continue
SearchEnemyHead()
if (GetKeyState("LButton", "P") && (LeftClick || RightClick)) {
MouseGetPos, X_Start, Y_Start
MoveMouse := true
Sleep, 100
}
else {
MoveMouse := false
}
}
[Mod action: Moved topic to the v1 section since this is v1 code. The main section is for v2.]