Advertisement
cemxokenc

Warcraft III Masin RPG Multibox Farm

Apr 29th, 2025 (edited)
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Get the list of Warcraft III windows as an Array
  2. warcraftWindows := GetWarcraftWindows()    
  3.  
  4. Loop
  5. {
  6.     ; Loop through each Warcraft III window
  7.     for index, winID in warcraftWindows
  8.     {
  9.         ; Activate the current Warcraft III window
  10.         Sleep, 1000  ; Wait before switching windows       
  11.         WinActivate, ahk_id %winID%
  12.         WinWaitActive, ahk_id %winID%
  13.         Sleep, 2000  ; Ensure window is fully active
  14.  
  15.         ; Record the current latest file in the folder
  16.         prevLatestFile := GetLatestFile("D:\screenshots")
  17.        
  18.         ; Take screenshot of the active window
  19.         Send, {Alt down}{PrintScreen}{Alt up}
  20.         Sleep, 1000
  21.         Send, {Enter}-quest{Enter}  ; Execute -quest after screenshot
  22.  
  23.         ; Wait for screenshot processing (increase sleep if needed)
  24.         Sleep, 2000
  25.  
  26.         ; Wait until a new file (new screenshot) is detected
  27.         latestFile := prevLatestFile
  28.         newTimeout := A_TickCount + 5000  ; Try up to 5 seconds
  29.         while (A_TickCount < newTimeout && latestFile = prevLatestFile)
  30.         {
  31.             Sleep, 500
  32.             latestFile := GetLatestFile("D:\screenshots")
  33.         }
  34.  
  35.         ; OCR recognition using Tesseract on the new screenshot
  36.         OutputTextPath := "D:\screenshots\output_text"
  37.         RunWait, tesseract.exe %latestFile% %OutputTextPath%, , Hide    
  38.  
  39.         ; Read text from the OCR output file
  40.         OutputTextPath := "D:\screenshots\output_text.txt"
  41.         FileRead, outputText, %OutputTextPath%
  42.  
  43.         ; Search for six digits with spaces around them        
  44.         RegExMatch(outputText, "[\s\-_—](\d{6})\s\(", match)
  45.         if (match1)
  46.         {        
  47.             Send, {Enter}-afk %match1%{Enter}
  48.            
  49.             ; Add code into log-file
  50.             FileAppend, -afk %match1%`n, D:\screenshots\afk_codes.txt
  51.  
  52.             ; Additional commands after found afk code
  53.             Sleep, 1000
  54.             Send, {Enter}-greed{Enter}
  55.             Sleep, 1000
  56.             Send, {Enter}-str{Enter}
  57.             Sleep, 1000
  58.             Send, {Enter}-save{Enter}
  59.             Sleep, 1000
  60.             Send, {Enter}-clear{Enter}
  61.         }
  62.     }
  63.  
  64.     ; Wait before starting the next cycle
  65.     Sleep, 2000
  66. }
  67.  
  68. GetWarcraftWindows()
  69. {
  70.     warcraftWindows := Array()  ; Use an Array instead of a List
  71.     WinGet, idList, List, Warcraft III
  72.     Loop, %idList%
  73.     {
  74.         winID := idList%A_Index%
  75.         warcraftWindows.Push(winID)
  76.     }
  77.     return warcraftWindows
  78. }
  79.  
  80. GetLatestFile(folderPath)
  81. {
  82.     latestFile := ""
  83.     latestTime := 0
  84.     Loop, Files, %folderPath%\*.png
  85.     {
  86.         if (A_LoopFileTimeModified > latestTime)
  87.         {
  88.             latestTime := A_LoopFileTimeModified
  89.             latestFile := A_LoopFileFullPath
  90.         }
  91.     }
  92.     return latestFile
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement