Advertisement
Braingame

Harry Potter: Hogwarts Mystery - AutoClicker

May 7th, 2019
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. ; Harry Potter: Hogwarts Mystery - AutoClicker
  3. ; Suitable for usage with Nox
  4. ;
  5. ; This script is a work in progress.
  6. ; Changes are likely to happen in order to ensure fast and reliable execution.
  7. ;
  8. ; Recommended values for Nox:
  9. ;   SleepDur := 40
  10. ;   ClickPerPosition := 3
  11. ;   RowCount := 5
  12. ;   ColumnCount := 10
  13. ;
  14. ; Recommended values for other emulators (BlueStacks, MEmu, etc.):
  15. ;   SleepDur := 1
  16. ;   ClickPerPosition := 2
  17. ;   RowCount := 5
  18. ;   ColumnCount := 10
  19. ;
  20. ; In both cases you can increase the execution speed tremendously by using
  21. ;   RowCount := 3
  22. ;   ColumnCount := 6
  23. ; However, this will lead to instances, where the script gets "stuck" on small objects.
  24. ;
  25. ;
  26. ; List of default keybindings:
  27. ;   Alt + q:    terminate script
  28. ;   F9:         toggle blue/red outline search
  29. ;   F11:        en-/disable basic AutoClicker
  30. ;   F12:        en-/disable class/quest AutoClicker
  31. ;  
  32. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33.  
  34. #NoEnv
  35. #Warn
  36. #maxThreadsPerHotkey, 8
  37. SendMode Input
  38.  
  39. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. ; Settings
  41. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42.  
  43. Activate := false       ; don't touch this
  44. SearchRed := false      ; default outline search (false -> blue, true -> red)
  45. SleepDur := 40          ; sleep duration (in ms) between clicks
  46. ClickPerPosition := 3   ; how often to click on one point
  47. RowCount := 3           ; how many search rows to split the screen into
  48. ColumnCount := 6       ; how many search columns to split the screen into
  49.  
  50. ; button coordinates (rel) for prompts and minigames (assumed 16:9 aspect ratio)
  51. ; [0.5, 0.5] -> 2nd reward
  52. ; [0.6, 0.8] -> 2nd answer
  53. ; [0.6, 0.5] -> General prompt for continuing (e.g. "Focus" or "Answer Question")
  54. PromptCoords := [[0.5, 0.5], [0.6, 0.8], [0.6, 0.5]]
  55.  
  56. ; limits (rel) for upper corners (assumed 16:9 aspect ratio)
  57. ; will be excluded from outline search
  58. RestrictedWidth := [0.2, 0.8]
  59. RestrictedHeight := 0.33
  60.  
  61. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62. ; Outline-search Optimization Guide:          
  63. ;
  64. ; short sleep duration:         faster clicking -> faster execution (i.e. progress)
  65. ; long sleep duration:          less demanding for your emulator -> avoids crashes
  66. ; few clicks per position:      less time wasted on non-registering outlines
  67. ; many clicks per position:     more likely to finish activties in one go
  68. ;                               better progress/click ratio
  69. ; low row/column values:        faster search -> faster execution (i.e. progress)
  70. ; high row/column values:       less likely to get stuck on non-registering outlines
  71. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72.  
  73. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74. ; Terminate the script
  75. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76.  
  77. !q::
  78. {
  79.     msgbox, ended
  80.     exitapp
  81. }
  82. return
  83.  
  84. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. ; Toggle blue/red outline search
  86. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87.  
  88. $f9::
  89. {
  90.     SearchRed := !SearchRed
  91. }
  92. return
  93.  
  94. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. ; En-/disable basic auto-clicking
  96. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97.  
  98. $f11::
  99. {
  100.     Activate := !Activate
  101.    
  102.     while (Activate) {
  103.         Click
  104.         Sleep, SleepDur
  105.     }
  106. }
  107. return
  108.  
  109. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110. ; En-/disable class/quest auto-clicking
  111. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  112.  
  113. $f12::
  114. {
  115.     WinGetPos, WinX, WinY, WinWidth, WinHeight, A
  116.     Activate := !Activate
  117.    
  118.     while (Activate) {
  119.         ; split search area in rows and columns
  120.         ; cursor can get stuck on thin clickable objects / horizontal edges (clicks don't trigger activity)
  121.         ; if cursor gets stuck in one area, it might find something to click in the next
  122.         Loop, %RowCount% {
  123.             StartHeight := WinHeight*(A_Index-1)/RowCount
  124.             EndHeight := WinHeight*A_Index/RowCount
  125.  
  126.             Loop, %ColumnCount% {
  127.                 StartWidth := WinWidth*(A_Index-1)/ColumnCount
  128.                 EndWidth := WinWidth*A_Index/ColumnCount
  129.  
  130.                 ; exclude upper left and upper right corner from search
  131.                 ; otherwise can lead to problems during potion classes
  132.                 if (StartHeight < RestrictedHeight*WinHeight) {
  133.                     if (EndWidth < RestrictedWidth[1]*WinWidth or StartWidth > RestrictedWidth[2]*WinWidth) {
  134.                         Continue
  135.                     } else if (StartWidth < RestrictedWidth[1]*WinWidth) {
  136.                         StartWidth := RestrictedWidth[1]*WinWidth
  137.                     } else if (EndWidth > RestrictedWidth[2]*WinWidth) {
  138.                         EndWidth := RestrictedWidth[2]*WinWidth
  139.                     }
  140.                 }
  141.  
  142.                 ; search for blue/red outline of clickable objects
  143.                 ; blue: classes + most quests, red: occasional quest
  144.                 ; F9 to toggle
  145.                 if (SearchRed)
  146.                     PixelSearch, ObjectX, ObjectY, StartWidth, StartHeight, EndWidth, EndHeight, 0xF2542B, 0, Fast RGB
  147.                 else
  148.                     PixelSearch, ObjectX, ObjectY, StartWidth, StartHeight, EndWidth, EndHeight, 0x46BFFF, 0, Fast RGB
  149.  
  150.                 ; don't click if no outline was found
  151.                 if ErrorLevel
  152.                     Continue
  153.                
  154.                 Loop, %ClickPerPosition% {
  155.                     Click, %ObjectX%, %ObjectY%
  156.                     Sleep, SleepDur
  157.                 }
  158.             }
  159.         }
  160.        
  161.         ; click potential buttons to proceed
  162.         For index, Coord in PromptCoords {
  163.             MouseMove, Coord[1]*WinWidth, Coord[2]*WinHeight, 0
  164.             Click
  165.         }
  166.     }
  167. }
  168. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement