Action Script - LastHIT

Ask gaming related questions (AHK v1.1 and older)
loneydrozhat
Posts: 2
Joined: 20 May 2018, 17:40

Action Script - LastHIT

21 May 2018, 12:40

Hello everyone,

I'm trying to do a functional script to "Kill" some character in-game when your life is low, but to this work fine, i need that script read how much life this character have.

Some like:

Code: Select all

F3::
	loop:
	if character_life <= 100 {
		MouseMove, x, y, 0
		Click right
	} else {
		Goto loop
	}
But, i don't know how capture this numbers "life of character".
Actually my AHK script search the life bar and then click, have some way to ImageSearch capture an image and convert in a number or another way to do this?

The game is league of legends, and i trying to do a last hit script.

Code: Select all

#Notenv
#SingleInstance force

~v::
	lasthit:
		ImageSearch, x, y, 1, 1, A_ScreenWidth, A_ScreenHeight, minionHP.png
		if !ErrorLevel{
			y:=y+30				
			MouseMove, x, y, 0
			Click right
			sleep 500
			Goto lasthit
		}
return
~F12::Suspend
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: Action Script - LastHIT

24 May 2018, 12:47

I have done this successfully. I can tell you right now that Imagesearch will be WAYYYYY too slow to be useful while trying to also play the game. PixelGetColor is also much too slow.
loneydrozhat
Posts: 2
Joined: 20 May 2018, 17:40

Re: Action Script - LastHIT

24 May 2018, 20:59

Ruevil2 wrote:I have done this successfully. I can tell you right now that Imagesearch will be WAYYYYY too slow to be useful while trying to also play the game. PixelGetColor is also much too slow.
Do you know another way to do this?
One exemple for that is "BoxBox", he play league of legends with a joystick, and use AHK for target selector, do you know something about that?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Action Script - LastHIT

25 May 2018, 02:07

Gdip_BitmapFromScreen(), Gdip_LockBits(), then devise an algorithm to query the pixels and determine what is a healthbar, what isn't and their respective values, and that might get you somewhere north of 50ms per iteration if your processor is any good.
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: Action Script - LastHIT

25 May 2018, 08:09

swagfag wrote:Gdip_BitmapFromScreen(), Gdip_LockBits(), then devise an algorithm to query the pixels and determine what is a healthbar, what isn't and their respective values, and that might get you somewhere north of 50ms per iteration if your processor is any good.
That's still way too slow. The problem becomes the combined time it takes for the pixel determination on top of taking control of the mouse, moving it, pressing A, clicking, moving back to original position. Even a combined delay of +100ms is too interrupting to gameplay and just results in getting you killed by your lane opponent. Then on top of this problem, last hitting is not always the highest priority. For example, if you are going to go for a kill to your lane opponent, you don't want your controls suddenly switching over to last hit a minion mid fight.

There is much more to consider here than just the speed of the pixel search that really complicates what would be a simple script otherwise. Personally I got this working(also got champ last hit too), but I couldn't get the total execution time any lower than about 150ms and that was much too interrupting to gameplay to be useful.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Action Script - LastHIT

25 May 2018, 08:25

i think a more sensible approach would be to implement some sort of a triggerbot; have holding some hotkey enter you in a "last hit mode", so to speak, and then youd hover over something thats about to die, do you pixelsearching(reduced search space, too), figure out what the health is and unleash the killing blow whenever it is appropriate.
that way you avoid getting screwed over by an automatic script in other situations when you dont wanna be lasthitting.
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: Action Script - LastHIT

30 May 2018, 10:06

swagfag wrote:i think a more sensible approach would be to implement some sort of a triggerbot; have holding some hotkey enter you in a "last hit mode", so to speak, and then youd hover over something thats about to die, do you pixelsearching(reduced search space, too), figure out what the health is and unleash the killing blow whenever it is appropriate.
that way you avoid getting screwed over by an automatic script in other situations when you dont wanna be lasthitting.
You already said this. I am telling you from experience and from doing this exact method that it is way too slow and interrupting to gameplay to be useful. If you can get something working that is >100ms feel free to share your code.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Action Script - LastHIT

30 May 2018, 12:52

i mean, how big are these healthbars anyway... on my [email protected] checking a 200x50 px screen clip takes 10-20ms

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen

#Include Gdip_All.ahk

pToken := Gdip_Startup()
OnExit(Func("cleanUp"))
DllCall("QueryPerformanceFrequency", "Int64*", frequency)

Esc::ExitApp
F1::
{
	DllCall("QueryPerformanceCounter", "Int64*", start)

	pBitmap := scanAroundCursor(200, 50)

	DllCall("QueryPerformanceCounter", "Int64*", stop)
	duration := (stop - start) * 1000
	duration /= frequency
	MsgBox % "Executed in " duration " ms."

	Gdip_SaveBitmapToFile(pBitmap, imgPath := "D:\healthbar.PNG")
	Gdip_DisposeImage(pBitmap)
	Run % imgPath
return
}

scanAroundCursor(w, h) {
	pBitmap := Gdip_BitmapFromScreen(getHpBarRect(w, h))
	Gdip_LockBits(pBitmap, 0, 0, w, h, Stride, Scan0, BitmapData)

	; ur HP determining algorithm goes here
	Loop % h
	{
		y := A_Index - 1
		Loop % w
		{
			x := A_Index - 1
			pixelARGB := Gdip_GetLockBitPixel(Scan0, x, y, Stride)
		}
	}

	Gdip_UnlockBits(pBitmap, BitmapData)

	return pBitmap
}

getHpBarRect(w, h) {
	MouseGetPos, x, y
	x -= w // 2, y -= h // 2
	return Format("{}|{}|{}|{}", x, y, w, h)
}

cleanUp() {
	global pToken, pBitmap
	if (pBitmap)
		Gdip_DisposeImage(pBitmap)
	Gdip_Shutdown(pToken)
	ExitApp
}
Ruevil2
Posts: 173
Joined: 14 Jul 2014, 10:39

Re: Action Script - LastHIT

04 Jun 2018, 09:27

swagfag wrote:i mean, how big are these healthbars anyway... on my [email protected] checking a 200x50 px screen clip takes 10-20ms
You completely missed the point. It's not about how long the pixel/image/whatever search takes, it's about the total amount of time taken to perform the entire last hit action(healthbar search, mousemove, A down, mouseclick, mousemove back to original position). The healthbar discovery portion of performing a last hit is only a SMALL fraction of the problem at hand. The real issue becomes the time it takes to move the mouse and press the keys reliably and also quickly enough to return control to the player since League uses DirectInput style polling requiring keys/mouseclicks to be held down for 15-20ms each to be read by the client properly every time. This makes the grand total runtime of the script typically northward of 100ms as I stated, way too slow to be useful.

Secondarily the 'around the mouse' search style is not useful at all. The mouse needs to be directing the movement of the champion during the health bar search, basically constantly avoiding incoming fire from enemy champions. This makes the screen search area more like 25% of the screen at any given time since there is a mob of around a half dozen and any one could be the next last hit target. Attempting to direct multiple searches and direct your champion would be damn near impossible in League. I suggest you give league a try and these issues would become immediately apparent.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 69 guests