Help/Gaming

Ask gaming related questions (AHK v1.1 and older)
LuckyS1337
Posts: 55
Joined: 20 Mar 2023, 12:59

Help/Gaming

Post by LuckyS1337 » 26 Mar 2023, 03:40

Hello i have problem with this code.

I tried to change code "1" to code that breaks loop or return function up to 2 seconds, the problem is with that centerimgcoords, it totally skip that part, it doesn't click on image. Script should click in the center of found image. I can't do it. Can someone help

1. To change:

Code: Select all

Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 19, 79, 221, 340, C:\Users\user1\AppData\Roaming\Script\Images\All.png
CenterImgSrchCoords("C:\Users\user1\AppData\Roaming\Script\Images\All.png", FoundX, FoundY)
If ErrorLevel = 0
	Click, %FoundX%, %FoundY% Left, 1
Sleep, 5
}
Until ErrorLevel = 0
@@@@@@@@@@@@@@@@@@@@@@@@@@

2.one that is not working.

Code: Select all

image := "C:\Users\user1\AppData\Roaming\Script\Images\All.png" 

If !FileExist(image) { 

 Return
}

wait  := 2000
end   := A_TickCount + wait 
x1    := 19
y1    := 79
x2    := 221
y2    := 340

Loop { 
 Sleep 25
 ImageSearch ,,, x1, y1, x2, y2, % image
} Until !ErrorLevel || A_TickCount > end

If (ErrorLevel)
     return
Else 
If ErrorLevel = 0
CenterImgSrchCoords("C:\Users\user1\AppData\Roaming\Script\Images\All.png", FoundX, FoundY)
Click, %FoundX%, %FoundY% Left, 1
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 26854
Joined: 09 Sep 2014, 18:38

Re: Help/Gaming

Post by mikeyww » 26 Mar 2023, 10:51

Hello,

I recommend posting a script that the user can run to demonstrate the problem that you are having.

LuckyS1337
Posts: 55
Joined: 20 Mar 2023, 12:59

Re: Help/Gaming

Post by LuckyS1337 » 27 Mar 2023, 07:38

@mikeyww kinda hard because it's in game but all i want: click on image if it's found up to 2 seconds after i press hotkey

i want to change this code to another with 2 seconds timer

Code: Select all

; code to change
Loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 22, 92, 262, 341, C:\Users\User1\AppData\Roaming\Script\Images\All.png
CenterImgSrchCoords("C:\Users\User1\AppData\Roaming\Script\Images\All.png", FoundX, FoundY)
If ErrorLevel = 0
	Click, %FoundX%, %FoundY% Left, 1
Sleep, 30
}
Until ErrorLevel = 0
If ErrorLevel = 0
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

for example, this code below works 100% because it doesn't have an option click on image if found.


Code: Select all

image := "C:\Users\User1\AppData\Roaming\Script\Images\All.png" 

If !FileExist(image) { 

 Return
}

wait  := 2000
end   := A_TickCount + wait 
x1    := 165
y1    := 390
x2    := 361
y2    := 488

Loop { 
 Sleep 25
 ImageSearch ,,, x1, y1, x2, y2, % image
} Until !ErrorLevel || A_TickCount > end

If (ErrorLevel)
     return
Else 
If ErrorLevel = 0

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

User avatar
mikeyww
Posts: 26854
Joined: 09 Sep 2014, 18:38

Re: Help/Gaming

Post by mikeyww » 27 Mar 2023, 08:50

Code: Select all

; This script looks for an image for a defined amount of time
#Requires AutoHotkey v1.1.33
image := A_ScriptDir "\test.png"
x1    := 165
y1    := 390
x2    := 361
y2    := 488
wait  := 2000

If FileExist(image)
 img := imgSize(image)
Else MsgBox, 48, Error, File not found.`n`n%image%
SoundBeep 2000

F3::
SoundBeep 1500
end := A_TickCount + wait
Loop {
 Sleep 25
 ImageSearch , x, y, x1, y1, x2, y2, % image
} Until !ErrorLevel || A_TickCount > end
If !ErrorLevel {
 MouseClick ,, x + img.w / 2, y + img.h / 2
 SoundBeep 1000
} Else MsgBox 48, Error, Image not found!
Return

imgSize(img) { ; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=81665
 ; Returns an array indicating the image's width (w) and height (h), obtained from the file's properties
 SplitPath img, fn, dir
 objShell := ComObjCreate("Shell.Application")
 objFolder := objShell.NameSpace(dir), objFolderItem := objFolder.ParseName(fn)
 scale := StrSplit(RegExReplace(objFolder.GetDetailsOf(objFolderItem, 31), ".(.+).", "$1"), " x ")
 Return {w: scale.1, h: scale.2}
}

Post Reply

Return to “Gaming Help (v1)”