Tulfier
Good work ;)
Question: You search for resources according to their colors without giving x and y coordinates. So I understand that you are doing a global search on your screen. What is the processing time for finding the color on a map?
I did some tests on my side with windll.gdi32.GetPixel but it is rather long. So I'm curious how long your treatment lasts.
Sorry @Tulfier , when I said
You need to know what chroma pallet a specific resource uses, and search for it on the screen. If any resource is collectable, you can continue your route without wasting time clicking on empty resource spots.
I meant to say I search on specific x and y coordinates, not on the whole screen. Both my approaches check specific x and y coordinates, but the first one always clicks even if the resource has not spawn'd and the second approach checks if the resource is there so you can save between 3-5 seconds per resource spot. Anyways is a good question, and since there are some alternative solutions with python libraries and other stuff, I would want to share my approach. Mine is kinda inneficient considering the amount of time required to program it, but I think it is worth it considering how fast my script can be. Instead of searching on the whole screen, which can take quite a long time (if i'm not wrong, pixelsearchs AutoHotkey methods search line by line checking all the pixels) or doing search algorithms or image pattern recognition, I've made my script to only look in specific pixels. In other words, I have coded for every map of my route, the concrete locations where the resources spawn.
Example:
![[Image Introuvable]](https://i.imgur.com/whpLIh9.png)
With the spy window, I check the exact pixel or pixels where the chestnuts are, for every map. Then my colour checker method only checks if those specific pixels are that colour or other. Only if there is a match, the click is executed. Otherwise it continues to check the next pixel. So basically I dont "search", I "compare". I would code that map as follows:
; [1,30] map coordinates
Send {Shift down}
PixelGetColor, color, 567, 85, RGB
if checkColor(color) = 0
{
MouseMove, 567, 85,
Click
Sleep, 5000
}
check()
PixelGetColor, color, 871, 625, RGB
if checkColor(color) = 0
{
MouseMove, 871, 625,
Click
Sleep, 5000
}
.... and so on, all the trees coordinates
checkColor(color){
c := color
if RegExMatch(c, "^0x6.2.1.$")=1 or RegExMatch(c, "^0x5.2.1.$")=1
return 0
else
return 1
}
check(){
sleep, 500
if (checkFight() = 1)
{
Send {Shift up}
Sleep, 500
RunWait, fight.exe, %A_ScriptDir% ; we run the fight script to autofight the resource protector and wait till that script ends
Sleep, 3000 ;we wait 3 seconds because sometimes the end-of-combat interface laggs
Send {Enter} ;after the fight has ended, we send the enter key to close the end-of-combat interface
Sleep, 500
Send {Shift down}
Sleep, 500
}
return
}
checkFight(){ ;I think this method checks for the yellow button "ready" or something like that to know if you are starting a combat.
PixelGetColor, color, 160, 488, RGB
PixelGetColor, color2, 1732, 476, RGB
PixelGetColor, color3, 791, 1007, RGB
if (color = 0x000000 and color2 = 0x000000 and color3 = 0x92CA00)
return 1
else
return 0
}
So, why this approach?
- I coded this all on ahk scripts (AutoHotKey), so no python, no libraries, no aditional stuff needed.
- This method takes like 5 seconds to code per each resource (move the mouse to the resource coordinate, copy the coordinates into the script and repeat). By practising I have managed to code scripts of more than 1.000 lines in like 15-20 minutes.
- I can bet is way more faster than any librarie/algorithm search method, because you are directly telling the script where to search.
- Its true that you have spent maybe 10 minutes coding a route with 20 maps and 50 chestnuts, and manually inserting the coordinates, but the amount of time your CPU is gonna save running time consuming search algorithms I think its worth it.
- How fast it is? Well, lets find out. Lets get rid of the fight check() since its not part of the resource detection and lets measure the execution time of the 9 chestnuts on [-1,30] with this approach
![[Image Introuvable]](https://i.imgur.com/DwowsYx.png)
StartTime := A_TickCount
PixelGetColor, color, 567, 85, RGB
if checkColor(color) = 0
{
; I have left this empty since we want to measure the execution time without waiting for the resource to be collected
; we are only counting how long it takes to search and compare colours of the 9 trees
}
another 8 chestnut comparisons here, all calling checkColor()
ElapsedTime := A_TickCount - StartTime
MsgBox % ElapsedTime
Cliquez pour révéler
Cliquez pour masquer
![[Image Introuvable]](https://i.imgur.com/qGJff84.png)
I have run the script like 20 times, and I always get execution times between 100ms and 200ms for 9 resource checks, and the most common value was 156ms. It depends on how busy your CPU is, and how good your CPU is. Mine is and i3 from 2014, and I'm running Mozilla with 9 tabs, Chrome with 2 tabs (Imgur doesnt work on Mozilla idk why), Discord, Paint 3D and Notepad++ so I think we can lower the execution time some ms.
Anyways 156ms / 9 chestnuts = 17,33 ms per resource. Is that fast enough? I'm quite sure it is.
To sum up:
- Is it fun to program? No
- Is it an elegant solution? No
- Requires to program complex search methods? No
- Requires external libraries/languages like python? No
- Is it fast? Yes
- You can apply this approach to collect fish, minerals , trees, plants...
Thanks to @valchimiiste for helping as well, I will check those python libraries.