Easy AHK Script to auto heal at certain HP for D4

07/10/2023 22:38 tomwa333#1
Hey there - here is a script I coded in a few minutes for 1440p. Feel free to take this source and use how you want. Has a nice overlay included just change coordinates and colors if needed. :mofo:

Code:
; Diablo 4 HP

;\\ Some fancy diablo 4 magic with ahk - checks hp and heals at a certain point
;\\ I made this for 1440p but can easily determine window size and automatically find positions with a few more minutes of work


#NoEnv
CoordMode, Mouse, Client
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetBatchLines -1
SetMouseDelay, 0


; some fancy gui overlay magic - pauses in menus/vendors
go:
text1 = Launched...
WinActivate, ahk_class SunAwtFrame 
WinGetPos, wx, wy, wwx, wwy,ahk_class SunAwtFrame             
Gui +ToolWindow -Caption +Owner +border +AlwaysOnTop
Gui, Color, c262322
Gui, Font, s10 cB5B5B5
Gui Add, Text, x5 y-1 w120 h23 +0x200, Diablo 4 Tool
Gui Add, Button, x117 y54 w80 h23 gstart, Start
Gui Add, Text, x7 y28 w120 h24 +0x200, Status:
Gui, Font, c00FF00
Gui Add, Text, x58 y29 w120 h23 +0x200 vtext1, %text1%
wy += 1330
wx += 20
Gui Show, x%wx% y%wy% w206 h84, Tom's Agility
return



start:
guicontrol,, text1, Getting HP Status...
WinACtivate, ahk_class Diablo IV Main Window Class
loop{
WinACtivate, ahk_class Diablo IV Main Window Class
PixelSearch, px, py, 812, 1296, 847, 1315, 0x9E3038, 25, Fast RGB ; coords for HP
    If (errorlevel = 0)
        {
            guicontrol,, text1, Healthy...
            WinACtivate, ahk_class Diablo IV Main Window Class
        }
    If (errorlevel = 1)
        {
            sleep 300
            Pixelsearch, px2,py2, 2488, 19, 2553, 69, 0xB64131, 15, Fast RGB ; coords for tab menu exit button
            If (errorlevel = 0)
                {
                    guicontrol,, text1, Paused.
                    WinActivate, ahk_class Diablo IV Main Window Class
                }
            If (errorlevel = 1)
                {

                    Pixelsearch, px2,py2, 2514, 83, 2555, 115, 0x842422, 15, Fast RGB ; coords for shop inventory exit button
                    If (errorlevel = 0)
                        {
                            guicontrol,, text1, Paused.
                            WinACtivate, ahk_class Diablo IV Main Window Class
                        }
                        If (errorlevel = 1)
                            {
            guicontrol,, text1, Healing...
            WinACtivate, ahk_class Diablo IV Main Window Class
            Send {XButton1} ; potion bind
                }
        }
    }
    }
return

F9::Exitapp
Enjoy :handsdown:
07/11/2023 08:38 mojoe87#2
There have been several bans using ahk.