Advertisement
Guest User

AutoHotKey Shinra's Finest script

a guest
Nov 22nd, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv
  2. SetWorkingDir %A_ScriptDir%
  3. ;Sets the working directory to be where the script is located.
  4. CoordMode, Mouse, Window
  5. ;Lets the finding of X and Y to be determined by the mouse's coordinates on the functions below.
  6. SendMode Input
  7. #SingleInstance Force
  8. SetTitleMatchMode 2
  9. #WinActivateForce
  10. SetControlDelay 1
  11. SetWinDelay 0
  12. SetKeyDelay -1
  13. SetMouseDelay -1
  14. SetBatchLines -1
  15. #Persistent
  16.  
  17. #Include %A_ScriptDir%\FindTextLib.ahk
  18.  
  19. ;;;#ME: They're 1920x1080, I'm 1366x768
  20. ;;;#ME: 1920 is 1.4x 1366, or 0.711
  21. ;;;#ME: 1080 is 1.4x 768, or 0.711
  22.  
  23. global WidthRatio := A_ScreenWidth / 1920
  24. global HeightRatio := A_ScreenHeight / 1080
  25.  
  26. ;;; This was generated by the FindText AHK script/library: https://autohotkey.com/boards/viewtopic.php?t=17834
  27. global JumpText:="|<Jump text>*106$45.zzzzzzzzzzzzzzzzkDzzzzzs0zzzzzzDbzzzzztyTzzzzyMk0000Tn600000yMzzyxzbm4zzzzywk2A030Ta0l0003wV48EU4Dg0X6A1XlWAMlU8SwM7CQ06j74tnY7pkzzzzXswDzzSwy7zz003a0zzw00Dk7zzk01y0zzzzzsTw"
  28. global EnterText:="|<Enter text>*159$33.zzzzzw3zzzzUTzzzxzzzzzjzxzzxy3339UGNn8gytiNDjrBk9xytiTDjrBndw2tX1Dzzzzzw"
  29. global PartyScreenNextText:="|<Party screen next text>*152$33.rxzzzyTbzzzlwzzzy7bzzbowsnYCnY2N7rAaMQywY3bbrkbwQyy4v9brskHgDzzzzzzzzzzw"
  30. global RemoveRWText:="|<Remove RW text>*134$47.zzzzzzzzzzzzzzzz1zzzzzzynzzzzzzxrzzzzzzvC60A4u3ktYrHZZrck/ib9MDRbrRCMrytiivQnbxt1Rq3rVzzzzzzzzzzzzzzzz"
  31. global GoText:="|<Go! text>*154$28.zzzzzwzvzy0w1tlvXXbDyTaNznyNbzDtaS4zatyHyPntbtz7aCDy0Q1tzzzzzzzzzs"
  32. global RoundsText:="|<Rounds text>*112$36.700030Tk007UTs00DUENByAwHDzzwyHAmEkXE8GEU3EFGG47P1GGAXv8EGVHvgsKlbzzzzzzzzzzzzU"
  33. global BeginBattleText:="|<Begin Battle text>*150$68.zzzzzzzzzzzsDzzzzw7zzwy1zzvzz0zzzDaTzyzzrDzxntbzzzzxnziQyFks/1z8kk1AUNYanDkNAtmNW1RhnxnvCQWQbkPQzSEnb9b9yCrDrZgtmN39DhnwWP/Im1kkPQz1kMlCzzxnzzzzzzzzzyQzzzzzzzzzzkTzzzzzzzzzyDzzzzzzzzzzzzzzzzzzy"
  34.  
  35. global OutsideBattleSteps := [{"Description": "This check is for the Green Shinra's finest event box."
  36.                               ,"FindText args": [751, 259, 150000, 150000, 0, 0, JumpText]
  37.                               ,"Wait ratio": 0.4}
  38.                              ,{"Description": "Clicks the Enter Dungeon button."
  39.                               ,"FindText args": [744, 592, 150000, 150000, 0, 0, EnterText]
  40.                               ,"Wait ratio": 0.8}
  41.                              ,{"Description": "Clicks the Next button."
  42.                               ,"FindText args": [682, 648, 150000, 150000, 0, 0, PartyScreenNextText]
  43.                               ,"Wait ratio": 0.8}
  44.                              ,{"Description": "#ME: Unselect the RW"
  45.                               ,"FindText args": [843, 355, 150000, 150000, 0, 0, RemoveRWText]
  46.                               ,"Wait ratio": 0.1}
  47.                              ,{"Description": "Clicks the GO! button."
  48.                               ,"FindText args": [683, 648, 150000, 150000, 0, 0, GoText]
  49.                               ,"Wait ratio": 0.4}
  50.                              ,{"Description": "#ME: Clicks the 'Rounds' text on boss platform"
  51.                               ,"FindText args": [704, 353, 150000, 150000, 0, 0, RoundsText]
  52.                               ,"Wait ratio": 0.4}
  53.                              ,{"Description": "Clicks the begin battle button."
  54.                               ,"FindText args": [771, 494, 150000, 150000, 0, 0, BeginBattleText]
  55.                               ,"Wait ratio": 0.8
  56.                               ,"Done?": true}]
  57.  
  58. global AttackText:="|<Attack text>*129$40.yTzzzvztzzzzjzXzzzyzwD4QyPjqMEVUgyNrDqS7s7QwPszDBnhjVwyrgqSnrt68A/bzzzzzzs"
  59. global GuardScorpionLeg:="|<Guard Scorpion front left leg>*44$71.zzzzs00Tzzzzzzzzk00zzzzzzzzzk01zzzzzzzzzk03zzzzzzzzzU07zzzzzzzzz00zzzzzzzzzy01zzzzzzzzzw03zzzzzzzzzs07zzzzzzzzzw0zzzzzzzzzzs1zzzzzzzzzzkDzzzzzzzzzzUTzzzzzzzzzzkzzzzzzzzzzzVzzzzzzzzzzzTzzzzzzzzzzyzzzzzzzzzzzxzzzzzzzzzzzvzzzzzzzzzzzzzzzzzzzzzzyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
  60. global ResultsText:="|<ResultsText>*138$56.zzzzzzzzzw3zzzzyTzz0TzzzzbzznbzzzztzzwtzzzzyRzzCTXstva33m7kA6St0UQ3tnDbiNtz8yQntvaSDnb0CCStbkwstzlbiNz7DCTyNvaTtntU8a8tUYQyA31kCQ8DzzzzzzzzzU"
  61.  
  62. F1::
  63. ;Press F1 to start your macro.
  64. Macro1:
  65. CoordMode, Pixel, Window
  66. WinActivate, NoxPlayer ahk_class Qt5QWindowIcon
  67. Sleep, 350
  68.  
  69. Loop
  70. {
  71.   mainloopstart:
  72.  FoundX := 0
  73.   FoundY := 0
  74.  
  75.   if (NOT GetIntoBattle()) {
  76.     return
  77.   }
  78.  
  79.   WorthyBoss := 0
  80.  
  81.   Loop
  82.   {
  83.     battleloop:
  84.    ;Checks if the fight has ended and you are in the champion screen.
  85.     ;If it is, it will click and check whether it should return to the beginning of the loop.
  86.     if (FindText(575, 92, 150000, 150000, 0, 0, ResultsText)) {
  87.       Goto, resultsloop
  88.     } else {
  89.       PixelSearchRelative(FoundX, FoundY, 991, 903, 991, 903, "0xA8A8A8", 10, "Fast")
  90.    
  91.       ;Checks if your turn available by ensuring the 2nd ability slot includes the color white that is on the outer ring of the ability.
  92.       if (ErrorLevel = 0) { ;If the turn is available..
  93.         Sleep, 250 ;;;#ME: Wait for text to bounce in
  94.         if (FindText(507, 672, 150000, 150000, 0, 0, AttackText)) { ;If the text "Attack" is visible, burst mode is inactive
  95.           ClickRelative(1131, 816, 1)
  96.           ;Click the BSB button
  97.           Sleep, 300
  98.           ;Left click on bsb. Repeat the loop.
  99.         } else { ;If it doesn't say "Attack", meaning the burst is active..
  100.           ;PixelSearchRelative(FoundX, FoundY, 847, 480, 847, 480, "0x0F0A0A", 10, "Fast")
  101.           ;Check tank
  102.           ;If ErrorLevel = 0
  103.           ;{
  104.           ;  WorthyBoss += 1
  105.           ;}
  106.        
  107.           ;~ PixelSearchRelative(FoundX, FoundY, 770, 467, 770, 467, "0x2534BE", 10, "Fast")
  108.           ;~ ;Check Guard Scorpion
  109.           ;~ If ErrorLevel = 0
  110.           if (FindText(611, 352, 150000, 150000, 0, 0, GuardScorpionLeg)) {
  111.             WorthyBoss += 1
  112.           }
  113.          
  114.           ;First we check if it is a worthy boss. There is a static spot on this boss.
  115.           ;You can add one more counter if you want to do it for the other bosses as well, just have to find a good pixel.
  116.        
  117.           if (WorthyBoss > 0) {
  118.             ;If we confirmed it is this boss..
  119.             ClickRelative(726, 840, 1)
  120.             Sleep, 300
  121.             WorthyBoss := 0
  122.             ;Left click on cmd1. Repeat the loop.
  123.           } else {
  124.             ClickRelative(827, 830, 1)
  125.             Sleep, 300
  126.             ;Left click on cmd2. Repeat the loop.
  127.           }
  128.         }
  129.       }
  130.     }
  131.   }
  132.  
  133.   resultsloop:
  134.  Loop
  135.   {
  136.     Sleep, 100
  137.     PixelSearchRelative(FoundX, FoundY, 860, 390, 860, 390, "0x0D2910", 10, "Fast")
  138.      
  139.     if (ErrorLevel = 0) { ;Checks if the Shinra screen is there.
  140.         Goto, mainloopstart
  141.     } else if (ErrorLevel = 1) {
  142.       Sleep, 1500
  143.       ClickRelative(885, 840, 2)
  144.       Sleep, 1500
  145.       ClickRelative(885, 840, 2)
  146.       ;Clicks the next button
  147.     }
  148.   }
  149. }
  150. Return
  151.  
  152. F2::ExitApp
  153.  
  154. F3::Pause
  155.  
  156. MyDebug(MyText)
  157. {
  158.   ToolTip, %MyText%
  159.   SetTimer, RemoveToolTip, 5000
  160. }
  161.  
  162. PixelSearchRelative(byRef Out1, byRef Out2, X1, Y1, X2, Y2, color, tol, opt)
  163. {
  164.   PixelSearch, FoundX, FoundY, X1*WidthRatio-10, Y1*HeightRatio-10, X2*WidthRatio+10, Y2*HeightRatio+10, %color%, tol, %opt%
  165.   ;MyDebug("Error level was: " ErrorLevel)
  166. }
  167.  
  168. ClickRelative(RelativeX, RelativeY, Count)
  169. {
  170.   XClickLocation := RelativeX * WidthRatio
  171.   YClickLocation := RelativeY * HeightRatio
  172.   ;;;#ME: MyDebug("Going to click at " XClickLocation ", " YClickLocation)
  173.   Click, %XClickLocation%, %YClickLocation%, Left, %Count%
  174. }
  175.  
  176. FindTextDebug(X, Y, Width, Height, Err1, Err0, TextToFind)
  177. {
  178.   ok := FindText(X, Y, Width, Height, Err1, Err0, TextToFind)
  179.   if (ok) {
  180.     return ok
  181.   } else {
  182.     MyDebug("Couldn't find the text :(")
  183.   }
  184. }
  185.  
  186. ClickFindTextResult(FindTextResult)
  187. {
  188.   if (FindTextResult) {
  189.     CoordMode, Mouse
  190.     X := FindTextResult.1.1, Y:=FindTextResult.1.2, W:=FindTextResult.1.3, H:=FindTextResult.1.4, X+=W//2, Y+=H//2
  191.     Sleep, 250
  192.     Click, %X%, %Y%, Left, 2
  193.   }
  194.   return FindTextResult
  195. }
  196.  
  197. GetIntoBattle()
  198. {
  199.   while (true) {
  200.     for StepNum, Step in OutsideBattleSteps {
  201.       if (ok := FindText(Step["FindText args"]*)) {
  202.         ClickFindTextResult(ok)
  203.         WaitTime := 5000 * Step["Wait ratio"]
  204.         Sleep, %WaitTime%
  205.        
  206.         if (Step["Done?"]) {
  207.           return true
  208.         } else {
  209.           break
  210.         }
  211.       }
  212.     }
  213.   }
  214. }
  215.  
  216. RemoveToolTip:
  217. SetTimer, RemoveToolTip, Off
  218. ToolTip
  219. return
  220.  
  221. ;Edit log: 1. /u/spirialis, 2. /u/richiealvian, 3. /u/MattDarling
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement