Subroutine not working when if condition is off.

Ask gaming related questions (AHK v1.1 and older)
BlazerSirus
Posts: 3
Joined: 16 Apr 2021, 20:14

Subroutine not working when if condition is off.

Post by BlazerSirus » 17 Apr 2021, 10:15

Hi, i made this code with the idea that:

1)When the pixelsearch result is positive, it hits (pressing E), and it stops when this is no longer true.
2) when it is no longer true, keep pressing L

The reason: i trying to do a bot that keep pressing L (to target the enemy), and it targets, pixelsearch gets the enemy life color (red) and keep hitting until this color go out (the enemy dies). When it dies, it go back to pressing L. (I cant count the time it takes to kill the enemy, cuz is a mmo, so it depends on number of players, gears and etc.

The part where it hits when the enemy is target is working fine, but it wont ever press L to target. I feel like is a code logic issue, but cant seem to find the error.
Can anyone help me?
I tried putting a else { Settimer, pressL, 100} after the if. Tried putting a settimer inside the If loop ( but it just stops pressing L when the enemy dies).

Code: Select all

#SingleInstance Force

keydelay = 50
weapondelay = 400

; color  b92929
;smallerframe x1y1x2y2: 1114, 74. 1087,105

-::
SetTimer, pressL, 1000
Loop,
{
	Sleep, 500
	PixelSearch, 1114, 74, 1087, 105, 0xb92929, 5, rgb
	if (ErrorLevel = 0)
	{
		
	SendEvent {E down}
	Sleep, % keydelay
	SendEvent {E up}
	
}

}
return

pressL:

	SendEvent {L down}
	Sleep, % keydelay
	SendEvent {L up}
return
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Subroutine not working when if condition is off.

Post by mikeyww » 17 Apr 2021, 12:36

Here is the syntax for PixelSearch.

Code: Select all

PixelSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID [, Variation, Mode]
Post Reply

Return to “Gaming Help (v1)”