Need help with simple battleloop with pixelsearch

Get help with using AutoHotkey and its commands and hotkeys
ozyank
Posts: 3
Joined: 25 Aug 2017, 00:01

Need help with simple battleloop with pixelsearch

30 Aug 2017, 02:02

Hi,

I've created a (very) simple battleloop for a game that is intended to work as follows:
1) Press F3
2) If an ability is available, send the designated key
3) If it's not available, check the next ability and so on.

Availability is determined via a pixelsearch.

What is working: all pixelsearches work and the first ability, if its available, always fires when F3 is pressed.

What isn't working: the Attack() function doesn't move through the different abilities, it only fires off the first one ("Ability1").

I'm very new to scripting/programming so appreciate any advice as I'm sure I've missed something really basic. I'm not looking to optimise the battleloop for now, just to get this sequence working after which I'll start optimising it for actual gameplay.

Code: Select all

F3::
Attack()  ;;Returns the key for the first available ability
{
   If Available("Ability1")
   {
		Send, 1
		Sleep, 25
		Return 1
   }
   Else If Available("Ability2")
   {
		Send, 3
		Sleep, 25 
		Return 1
   }
   Else If Available("Ability3")
   {
		Send, 4
		Sleep, 25
		Return 1
   }
   Else If Available("Ability4")
   {
		Send, 4
		Sleep, 25 
		Return 2
   }
   
Return 0

}

Available(Ability)  ;;checks if the ability passed from Attack() is available (off timer) and returns a 1 if it is.
{ 
	If Ability = Ability1
	CoordMode, Pixel, Window
	PixelSearch, FoundX, FoundY, 1119, 1308, 1160, 1336, 0x97834A, 80, Fast RGB
	If ErrorLevel = 0
	{
		Return 1
	}
	Else If Ability = Ability2
	CoordMode, Pixel, Window
	PixelSearch, FoundX, FoundY, 1236, 1316, 1271, 1344, 0xCB8665, 80, Fast RGB
	If ErrorLevel = 0
	{
		Return 1
	}
	Else If Ability = Ability3
	CoordMode, Pixel, Window
	PixelSearch, FoundX, FoundY, 1294, 1316, 1327, 1349, 0xA27E4F, 80, Fast RGB
	If ErrorLevel = 0
	{
		Return 1
	}
	Else If Ability = Ability4
	CoordMode, Pixel, Window
	PixelSearch, FoundX, FoundY, 1294, 1316, 1327, 1349, 0xA27E4F, 80, Fast RGB
	If ErrorLevel = 0
	{
		Return 1
	}

	Return 0
}
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Need help with simple battleloop with pixelsearch

30 Aug 2017, 07:07

Looks like your Available function has some syntax issues. You are missing Brackets where they are needed, and have a few that aren't needed, and checking if a value equals a string you need to use quotes.

Try this and see if it works:

Code: Select all

Available(Ability)  ;;checks if the ability passed from Attack() is available (off timer) and returns a 1 if it is.
{ 
	If (Ability = "Ability1") {
		CoordMode, Pixel, Window
		PixelSearch, FoundX, FoundY, 1119, 1308, 1160, 1336, 0x97834A, 80, Fast RGB
		If ErrorLevel = 0
			Return 1
	}
	Else If (Ability = "Ability2") {
		CoordMode, Pixel, Window
		PixelSearch, FoundX, FoundY, 1236, 1316, 1271, 1344, 0xCB8665, 80, Fast RGB
		If ErrorLevel = 0
			Return 1
	}
	Else If (Ability = "Ability3") {
		CoordMode, Pixel, Window
		PixelSearch, FoundX, FoundY, 1294, 1316, 1327, 1349, 0xA27E4F, 80, Fast RGB
		If ErrorLevel = 0
			Return 1
	}
	Else If (Ability = "Ability4") {
		CoordMode, Pixel, Window
		PixelSearch, FoundX, FoundY, 1294, 1316, 1327, 1349, 0xA27E4F, 80, Fast RGB
		If ErrorLevel = 0
			Return 1
	}

	Return 0
}
ozyank
Posts: 3
Joined: 25 Aug 2017, 00:01

Re: Need help with simple battleloop with pixelsearch

30 Aug 2017, 17:23

Thanks for pointing that out Nightwolf85. I made the modifications but unfortunately it's still just firing off the first ability. Does it look like I'm missing anything else?

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Lukk54, xMagicWarriorx and 42 guests