Cuphead Death Counter

Ask gaming related questions
cmdbutton
Posts: 6
Joined: 05 Oct 2019, 21:36

Cuphead Death Counter

05 Oct 2019, 21:45

Hi, I am new to AHK and I have gotten stuck on my 1st script, I am trying to make an automatic cuphead death counter for my wifes Twitch stream. I have got the code to detect the death and save as text file however I am getting random numbers when I test the script. I don't think I am too far off. I need the script to only add 1 point to the text file even if my wife takes leaves it on the death screen. Any help would be amazing, maybe I am doing it completely wrong? also tried to program it so it only searches the bottom left corner but it only works if I search whole screen? maybe I am doing the cords wrong?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


while !winExist("Cuphead")
    sleep 200
	
	
Loop
{
	ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *30 %A_ScriptDir%\dead.png
	if ErrorLevel = 0
    break ; image was found break loop and continue
}


 ; auto-execute section:
IfNotExist, %A_ScriptDir%\counter.txt
{
	FileAppend, 1, %A_ScriptDir%\counter.txt
	
}
else
{
	FileReadLine, OutputVar, %A_ScriptDir%\counter.txt, 1
	NewOutputVar := OutputVar+1
	FileDelete, %A_ScriptDir%\counter.txt
	FileAppend, %NewOutputVar%, %A_ScriptDir%\counter.txt
	
}

; this too check if the image is still on the screen if not restart the process of watching for new death
while !winExist("Cuphead")
    

Loop
{
	ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *30 %A_ScriptDir%\dead.png
	if ErrorLevel = 1
	break
}

sleep 2000
reload
gregster
Posts: 3379
Joined: 30 Sep 2013, 06:48

Re: Cuphead Death Counter

05 Oct 2019, 22:21

Welcome to the forum!
cmdbutton wrote:
05 Oct 2019, 21:45
I am getting random numbers when I test the script. [...] maybe I am doing the cords wrong?
By default, Imagesearch will use coordinates which are "relative to the active window unless CoordMode was used to change that." This includes the coordinates that determine the search area. So, you should probably add Coordmode, Pixel, Screen at the top of your script to get consistent results (not depending on the active window).

The second while !winExist("Cuphead") line I do not understand. You want to loop another Imagesearch while the 'Cuphead' window does NOT ( ! ) exist ? Is the logical NOT correct here?
Or is there something missing? There is big space between the while line and the following loop which will be affected by it (and further up you are using this condition with sleep). Perhaps I am just not understanding how the game works...
cmdbutton
Posts: 6
Joined: 05 Oct 2019, 21:36

Re: Cuphead Death Counter

05 Oct 2019, 22:52

Thank you for your reply ok i will add that line to the top of the code and try...as for the secound search i needed a way for it to only add 1 point... if i didnt have the 2nd search when the script reload if the game is still on the death screen it will add another point, by doing if the dead.png is found do nothing else if its gone then reload the script.
cmdbutton
Posts: 6
Joined: 05 Oct 2019, 21:36

Re: Cuphead Death Counter

05 Oct 2019, 22:54

I also think i have issues with the different sleeps just trying to figure it all out
cmdbutton
Posts: 6
Joined: 05 Oct 2019, 21:36

Re: Cuphead Death Counter

06 Oct 2019, 05:42

Ok so I have made some progress, I got the cords to work now by adding that code. The counter works however still having a hard time getting it to only trigger once... On Cuphead when the death screen appears you have to click "Retry". The below script works if retry is clicked within 5 secs, however this is not perfect as I would prefer it to check if the death screen is still on, then pause the script then when death screen is gone reload the script? if the player leaves the death screen open it adds 1 death every 5 secs.. I hope I am explaining this properly lol

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Coordmode, Pixel, Screen

while !winExist("Cuphead")
    sleep 200
	
	
Loop
{
	ImageSearch, FoundX, FoundY, 820, 700, 1100, 790, *20 %A_ScriptDir%\ret.png
	if ErrorLevel = 0
    break ; image was found break loop and continue
	
	
}


 ; auto-execute section:
IfNotExist, %A_ScriptDir%\counter.txt
{
	FileAppend, 1, %A_ScriptDir%\counter.txt
	
}
else
{
	FileReadLine, OutputVar, %A_ScriptDir%\counter.txt, 1
	NewOutputVar := OutputVar+1
	FileDelete, %A_ScriptDir%\counter.txt
	FileAppend, %NewOutputVar%, %A_ScriptDir%\counter.txt
	
}


sleep, 5000
reload
I tried adding this code to above the bottom sleep, 5000 but it does not work. any suggestions?

Code: Select all

while !winExist("Cuphead")
    

Loop 
{
	ImageSearch, FoundX, FoundY, 820, 700, 1100, 790, *200 %A_ScriptDir%\ret.png
	if ErrorLevel = 1
	break
}
Here is a video of what the issue is

[youtube]https youtu.be /-IIzX1SPM1k[/youtube] Broken Link for safety
Attachments
screen3.jpg
screen3.jpg (157.84 KiB) Viewed 363 times
ret.png
ret.png (10.01 KiB) Viewed 363 times
cmdbutton
Posts: 6
Joined: 05 Oct 2019, 21:36

Re: Cuphead Death Counter

06 Oct 2019, 05:59

hmm... maybe I can do it by pausing the script after it saves the score and then doing a keywait for controller button x pressed?
cmdbutton
Posts: 6
Joined: 05 Oct 2019, 21:36

Re: Cuphead Death Counter

06 Oct 2019, 07:34

Ok it works perfectly now. Does anyone know how to do KeyWait, Joy1, D OR enter button? not too important I don't know many people that play cuphead with keyboard but would be nice if both worked :D

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 43 guests