Really basic fishing

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ruathaz

Really basic fishing

16 Sep 2018, 01:14

This is really my first attempt at coding a AHK script. I finally hit a wall and cannot fathom what small errors I made. I am trying to get it to click when the area is no longer the color I set with ctrl+alt+z. I got it to either just keep clicking, or it won't click at all. I stole bits and pieces from other scripts I found, though I never tested them to see if they worked to begin with. Any help would be appreciated.

Code: Select all

#SingleInstance
#MaxThreadsPerHotkey 2
#NoEnv
SendMode Event
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, mouse, Screen

isFishing := False 

F6::
	isFishing := true
	MouseMove ButtonX, ButtonY
	startFishing()
return

F7::
	isFishing := false
return

^!z:: 
	MouseGetPos, LureX, LureY
	PixelGetColor, color, %LureX%, %LureY%, RGB
	CaX1 := (LureX - 1)
	CaY1 := (LureY - 1)
	CaX2 := (LureX + 1)
	CaY2 := (LureY + 1)
return

^!x:: 
MouseGetPos, ButtonX, ButtonY
return

startFishing() {
	global
	While isFishing {
		MouseMove ButtonX, ButtonY
		clickHook()
		sleep 5000
	}
}

clickHook() {
	global
	local pX = 0
	local pY = 0
	While isFishing {
		PixelSearch, pX, pY, CaX1, CaY1, CaX2, CaY2, color, 2, Fast RGB
		if !ErrorLevel {
			sleep 50 
		} else {
			MouseMove ButtonX, ButtonY
			Send, {LButton down}
			Sleep 150
			Send, {LButton up}
			break
		}
	}
}

F1::Suspend ;A precaution to break from loops during testing or some other reason.
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Really basic fishing

16 Sep 2018, 06:37

I kind of test your code (though I don't have any fishing game) and it seems to work, it start when I press F6 and ends when I press F7. I notised 2 things, it takes 5 sec to end the fishing since you have a "sleep 5000" in the startFishing() function, and when I restart the fishing with F6 it no longer seems to find the right color.

my little modifications to test

Code: Select all

#SingleInstance, force
#MaxThreadsPerHotkey 2
#NoEnv
SendMode Event
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, mouse, Screen

isFishing := False 

F6::
	isFishing := true
	MouseMove ButtonX, ButtonY
	startFishing()
	MsgBox f7 has been pressed
return

F7::
	isFishing := false
	MsgBox f7
return

^!z:: 
	MouseGetPos, LureX, LureY
	PixelGetColor, color, %LureX%, %LureY%, RGB
	CaX1 := (LureX - 1)
	CaY1 := (LureY - 1)
	CaX2 := (LureX + 1)
	CaY2 := (LureY + 1)
return

^!x:: 
MouseGetPos, ButtonX, ButtonY
return

startFishing() 
{
	global
	While isFishing {
		MouseMove ButtonX, ButtonY
		clickHook()
		sleep 5000
	}
}

clickHook() 
{
	global
	local pX = 0
	local pY = 0
	While isFishing 
	{
		PixelSearch, pX, pY, CaX1, CaY1, CaX2, CaY2, color, 2, Fast RGB
		if !ErrorLevel 
		{
			sleep 50 
			MsgBox !Errorlevel
		}
		else 
		{
			MouseMove ButtonX, ButtonY
			;~ Send, {LButton down}
			MsgBox else fishing
			Sleep 150
			;~ Send, {LButton up}
			break
		}
	}
}

F1::Suspend ;A precaution to break from loops during testing or some other reason.

esc::
ExitApp


Ruathaz
Posts: 16
Joined: 16 Sep 2018, 01:15

Re: Really basic fishing

16 Sep 2018, 11:24

I am trying to get it to keep running until I press F7. I have that long pause to give the game time to change colors back.
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Really basic fishing

16 Sep 2018, 11:27

yes but in my test it stopped running when I pressed f7
Ruathaz
Posts: 16
Joined: 16 Sep 2018, 01:15

Re: Really basic fishing

16 Sep 2018, 12:21

So I think I kinda see an issue. I dont have my game full screen. I am trying to get AHK to search those pixels on the screen regardless of what is in focus etc. I am not sure how to do that.
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Really basic fishing

16 Sep 2018, 12:42

You need to look at

Code: Select all

IfWinActive 
or

Code: Select all

WinActivate
I would think
Ruathaz
Posts: 16
Joined: 16 Sep 2018, 01:15

Re: Really basic fishing

16 Sep 2018, 16:17

This works perfectly when I have the game in full screen but idk how to get it to work when it's not.

Code: Select all

#SingleInstance, force
#MaxThreadsPerHotkey 2
#NoEnv
SendMode Event
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, mouse, Screen

isFishing := False 

F6::
	isFishing := true
	MouseMove ButtonX, ButtonY
	startFishing()
return

F7::
	isFishing := false
return

^!z:: 
	MouseGetPos, LureX, LureY
	PixelGetColor, color, %LureX%, %LureY%, RGB
	CaX1 := (LureX - 1)
	CaY1 := (LureY - 1)
	CaX2 := (LureX + 1)
	CaY2 := (LureY + 1)
	MsgBox CaX1 = %CaX1%, CaY1 = %CaY1%, CaX2 = %CaX2%, CaY2 = %CaY2%
return

^!x:: 
MouseGetPos, ButtonX, ButtonY
return

startFishing() {
	global
	While isFishing {
		MouseMove ButtonX, ButtonY
		clickHook()
		sleep 2500
	}
}

clickHook() {
	global
	local pX = 0
	local pY = 0
	While isFishing {
		PixelSearch, pX, pY, CaX1, CaY1, CaX2, CaY2, color, 2, Fast RGB
		if !ErrorLevel {
			sleep 50 
		} else {
			MouseMove ButtonX, ButtonY, 2
			Send, {LButton down}
			Sleep 150
			Send, {LButton up}
			break
		}
	}
}

F1::Suspend ;A precaution to break from loops during testing or some other reason.
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Really basic fishing

17 Sep 2018, 00:54

Try
CoordMode, mouse, Window

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, ShatterCoder and 144 guests