Advertisement
Guest User

Untitled

a guest
Jan 10th, 2012
1,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv
  2. #SingleInstance force
  3. #MaxThreadsBuffer On
  4. #MaxHotkeysPerInterval 1000000
  5. #HotkeyInterval 60000
  6.  
  7. CoordMode, Mouse, Screen
  8. SendMode, Input
  9. SetKeyDelay, -1
  10. SetMouseDelay, -1
  11.  
  12. ;--------------------------------------------------
  13. ; Settings
  14. ;--------------------------------------------------
  15.  
  16. ; Space Combat Bot
  17. spaceEnabled = 1 ; use space combat bot?
  18. missionId = 1 ; space combat mission
  19. runCount = 1 ; how many times to run the mission
  20.  
  21. ; Tradeskill Bot
  22. tradeskillEnabled = 0 ; use tradeskill bot?
  23. tradeskillBind = n ; key binding to open companion window
  24. ; tradeskill (0 = disabled, 1 = enabled)
  25. ; tradeskill tier (0 = default, 1 = 10-16, ... , 6 = 49-50)
  26. tradeskill = 1:0,0:0,0:0
  27. companion = 1,1,0 ; 0 = disabled, 1 = enabled (top to bottom)
  28. style = 1 ; 0 = pick tradeskill randomly, 1 = loop single tradeskill, 2 = do tradeskills in order (requires more than 1)
  29. diplomacyFaction = 0 ; only picks diplomacy missions based on faction (0 = disabled/any, 1 = republic, 2 = empire)
  30.  
  31. ; Record Bot
  32. auto_save = 1 ; automatically save recordings
  33. record_path = scripts ; the script save/load location
  34. inPlay = 0 ; internal script variable to determine if bot is currently playing a script
  35. inRecord = 0 ; internal script variable to determine if bot is currently recording a script
  36. recording = ; internal script variable to store the recorded script
  37.  
  38. ;--------------------------------------------------
  39. ; Bot Functions
  40. ;--------------------------------------------------
  41.  
  42. ; Some code from:
  43. ; http://www.autohotkey.com/forum/viewtopic.php?t=53196
  44.  
  45. ; Records the next space combat mission
  46. recordBot() {
  47.     global
  48.     ; Double check the bot is not active
  49.     if(inPlay) {
  50.         return
  51.     }
  52.     if(inRecord=2) {
  53.         ttHandler("Space mission is now being recorded", 3000)
  54.         RecordCount := 0
  55.         Sleep, 100
  56.         ; Timers
  57.         TimeMouseMove := A_TickCount
  58.         SetTimer, RecordMouseKey, 1
  59.         return
  60.     }
  61. }
  62.  
  63. ; Gets mouse movement for recording
  64. GetMouseMove(ByRef TimeMouseMove) {
  65.     LButton:=GetKeyState("LButton", "P")
  66.     RButton:=GetKeyState("RButton", "P")
  67.     MButton:=GetKeyState("MButton", "P")
  68.     MouseGetPos, x1, y1
  69.     TimeMouseMove:= A_TickCount
  70.     return, % x1 "|" y1 "|" LButton "|" RButton "|" MButton
  71. }
  72.  
  73. ; Saves the current recording memory to a .torbot script
  74. saveRecording() {
  75.     global
  76.     ; set recording status to off
  77.     SetTimer,RecordMouseKey,Off
  78.     InRecord := 0
  79.     Loop, % RecordCount
  80.     {
  81.         DataMouseKey .= MouseData_%A_Index%
  82.         DataMouseKey .= "`n"
  83.     }
  84.     if(!DataMouseKey) {
  85.         ttHandler("Error, there is no recording to save", 5000)
  86.         return
  87.     }
  88.     ; todo: generate random name based on mission id
  89.     script = %record_path%/mission%missionId%.torbot
  90.     ; save to .torbot file
  91.     FileDelete, %script%
  92.     FileAppend, %DataMouseKey%, %script%
  93.     ttHandler("Saved recording: (%script%)", 5000)
  94.     ; clear the recording
  95.     DataMouseKey =
  96.     return
  97. }
  98.  
  99. ; Handles loading, parsing, and running .torbot recordings
  100.  
  101. runBot(script) {
  102.     ; Check if bot is currently active
  103.     if(inPlay=1 || inRecord>0) {
  104.         return
  105.     }
  106.     ; Start the bot script
  107.     inPlay = 1
  108.     ; Set the default file position to 0
  109.     static Position = 0
  110.     ; Read the bot file
  111.     file = scripts/%script%.torbot
  112.     FileRead, BotScript, %file%
  113.     ; Loop the bot file
  114.     loop, Parse, BotScript, `n
  115.     {
  116.         Data_%A_index%:= A_LoopField
  117.         Count := A_Index
  118.     }
  119.     loop, % Count
  120.     {
  121.         MoveNow := A_TickCount
  122.         CCount := A_index
  123.         ; Mouse click down
  124.         StringSplit, MouseKeyInfo, Data_%CCount% , |
  125.         Mousemove, MouseKeyInfo1, MouseKeyInfo2, 0
  126.         ; Left mouse
  127.         if (MouseKeyInfo3 && Not WaitLMouseUp) {
  128.             MouseClick, Left, MouseKeyInfo1, MouseKeyInfo2, , 0, D
  129.             WaitLMouseUp=1
  130.             SetTimer, Left, 1
  131.         }
  132.         ; Right mouse
  133.         else if (MouseKeyInfo4 && Not WaitRMouseUp) {
  134.             MouseClick, right, MouseKeyInfo1, MouseKeyInfo2, , 0, D
  135.             WaitRMouseUp=1
  136.             SetTimer, Right, 1
  137.         }
  138.         ; Middle mouse
  139.         else if (MouseKeyInfo5 && Not WaitMMouseUp) {
  140.             MouseClick, Middle, MouseKeyInfo1, MouseKeyInfo2, , 0, D
  141.             WaitMMouseUp=1
  142.             SetTimer, Mid, 1
  143.         }
  144.         While ( A_TickCount - MoveNow  < MouseKeyInfo6) {
  145.             continue
  146.         }
  147.     }
  148.     ; Timer for left mouse
  149.     Left:
  150.         if (MouseKeyInfo3) {
  151.             Return
  152.         }
  153.         WaitLMouseUp:=0
  154.         MouseClick, Left, MouseKeyInfo1, MouseKeyInfo2, , 0, U
  155.         SetTimer, Left, Off
  156.     return
  157.     ; Timer for right mouse
  158.     Right:
  159.         if (MouseKeyInfo4) {
  160.             Return
  161.         }
  162.         WaitRMouseUp:=0
  163.         MouseClick, right, MouseKeyInfo1, MouseKeyInfo2, , 0, U
  164.         SetTimer, Right, Off
  165.     return
  166.     ; Timer for middle mouse
  167.     Mid:
  168.         if (MouseKeyInfo5) {
  169.             Return
  170.         }
  171.         WaitMMouseUp:=0
  172.         MouseClick, m, MouseKeyInfo1, MouseKeyInfo2, , 0, U
  173.         SetTimer, Mid, Off
  174.     return
  175. }
  176.  
  177. ;--------------------------------------------------
  178. ; Tradeskill Functions
  179. ;--------------------------------------------------
  180.  
  181. ; Handles the entire tradeskill process
  182.  
  183. tradeskillHandler() {
  184.     global
  185.     ; Turn config variables into arrays
  186.     StringSplit, arrCompanion, companion, `,
  187.     StringSplit, arrTradeskill, tradeskill, `,
  188.     ; Make sure there are no pending rewards
  189.     hasMissionComplete()
  190.     ; Loop companions
  191.     Loop, %arrCompanion0% {
  192.         tempCID=%a_index%
  193.         tempC:=arrCompanion%a_index%
  194.         ; If companion is enabled
  195.         if(tempC=1 AND hasActiveMission(tempCID)=false) {
  196.             Loop, %arrTradeskill0% {
  197.                 tempTSID=%a_index%
  198.                 tempTS:=arrTradeskill%a_index%
  199.                 StringReplace, tempTS, tempTS, :, `,, All
  200.                 StringSplit, currTradeskill, tempTS, `,
  201.                 if((currTradeskill1=1 AND style=0) || (currTradeskill1=1 AND style=1) || (currTradeskill1=1 AND style=2 AND tempTSID != last_tradeskill)) {
  202.                     ; Open the appropriate tradeskill based on array index
  203.                     openTradeskill(a_index, tempCID)
  204.                     ; Select a mission tier if above 0
  205.                     if(%currTradeskill2%<0) {
  206.                         selectMissionTier(currTradeskill2)
  207.                     }
  208.                     ; Run the mission
  209.                     startMission(1)
  210.                     ; Check if it matches correct diplomacy faction if enabled
  211.                     if(diplomacyFaction<0 AND diplomacyCheck()!=diplomacyFaction) {
  212.                         ; We don't want this, drop it and send it through the loop again
  213.                         dropMission(tempCID) ; send the companion id
  214.                         continue
  215.                     }
  216.                     break
  217.                 }
  218.             }
  219.             ; set the last tradeskill
  220.             if(style = 2) {
  221.                 last_tradeskill = %tempTSID%
  222.             }
  223.         }
  224.         ; Make sure there are no pending rewards
  225.         hasMissionComplete()
  226.     }
  227. }
  228.  
  229. ; Checks the faction for diplomacy mission
  230.  
  231. diplomacyCheck() {
  232.     global
  233.     ; Check the faction icon of the first quest mission
  234.     PixelGetColor, color, 693, 263
  235.     ; empire
  236.     if(color = "0x020182" AND diplomacyFaction = 2) {
  237.         return 2
  238.     ; republic
  239.     }else if(color = "0xF8CD97" AND diplomacyFaction = 1) {
  240.         return 1
  241.     ; non-diplomacy error
  242.     }else{
  243.         return 0
  244.     }
  245. }
  246.  
  247. ; Opens or closes the crew management window based on whether
  248. ; it is currently open or not.
  249.  
  250. crewManageToggle(toggle) {
  251.     global
  252.     PixelGetColor, color, 325, 374 ; crew management scroll bar
  253.     if(toggle = "on" AND color != "0xD8B455") {
  254.         SendInput, {%tradeskillBind%}
  255.         Sleep, 1000
  256.     }else if(toggle = "off" AND color = "0xD8B455") {
  257.         SendInput, {%tradeskillBind%}
  258.         Sleep, 1000
  259.     }
  260. }
  261.  
  262. ; Open the tradeskill window based specified tradeskill id
  263. ; and companion id
  264.  
  265. openTradeskill(id, companion) {
  266.     ; Open crew management window
  267.     crewManageToggle("on")
  268.     ; Determine x based on tradeskill id
  269.     if (id = 1) {
  270.         xPos = 117
  271.     }else if(id = 2) {
  272.         xPos = 154
  273.     }else if(id = 3) {
  274.         xPos = 196
  275.     }
  276.     ; Determine y based on companion id
  277.     if (companion = 1) {
  278.         yPos = 360
  279.     }else if (companion = 2) {
  280.         yPos = 422
  281.     }else if (companion = 3) {
  282.         yPos = 491
  283.     }
  284.     ; Open tradeskill window
  285.     MouseClick, left,  xPos,  yPos
  286.     Sleep, 1000
  287. }
  288.  
  289. ; Selects a mission level tier based on the
  290. ; specified mission tier id. See data.txt for
  291. ; more information.
  292.  
  293. selectMissionTier(id) {
  294.     ; Open Drop Down
  295.     MouseClick, left,  882, 241
  296.     Sleep, 1000
  297.     ; set the x position
  298.     xPos = 882
  299.     if (id = 1) {
  300.         yPos = 259
  301.     }else if (id = 2) {
  302.         yPos = 270
  303.     }else if (id = 3) {
  304.         yPos = 283
  305.     }else if (id = 4) {
  306.         yPos = 295
  307.     }else if (id = 5) {
  308.         yPos = 309
  309.     }else if (id = 6) {
  310.         yPos = 322
  311.     }
  312.     ; Select mission tier
  313.     MouseClick, left,  xPos,  yPos
  314.     Sleep, 1000
  315. }
  316.  
  317. ; Drops the current mission based on companion
  318. ; id
  319.  
  320. dropMission(id) {
  321.     ; set mouse xPos
  322.     xPos = 279
  323.     ; get yPos by companion id
  324.     if (id = 1) {
  325.         yPos = 350
  326.     }else if (id = 2) {
  327.         yPos = 414
  328.     }else if (id = 3) {
  329.         yPos = 478
  330.     }
  331.     ; drop the mission
  332.     MouseClick, left,  xPos,  yPos
  333.     Sleep, 1000
  334. }
  335.  
  336. ; Starts the companions mission based on
  337. ; specified mission id
  338.  
  339. startMission(id) {
  340.     ; Select mission
  341.     xPos = 808
  342.     if(id == 1) {
  343.         yPos = 289
  344.     }else if (id == 2) {
  345.         yPos = 303
  346.     }else if (id == 3) {
  347.         yPos = 471
  348.     }else if(id = 4) {
  349.         yPos = 535
  350.     }
  351.     ; Select mission
  352.     MouseClick, left,  xPos,  yPos
  353.     Sleep, 1000
  354.     ; Send companion
  355.     MouseClick, left,  923,  621
  356.     Sleep, 1000
  357.     ; Close window
  358.     crewManageToggle("off")
  359. }
  360.  
  361. ; Checks if there is less than a minute left on tradeskills. The
  362. ; bot uses this to determine if it should wait before going on the
  363. ; next space combat mission.
  364.  
  365. getMissionTimer() {
  366.     ; todo
  367. }
  368.  
  369. ; Checks if the specified companion id is currently on a tradeskill
  370. ; mission or not
  371.  
  372. hasActiveMission(id) {
  373.     ; set mouse xPos
  374.     xPos = 279
  375.     ; get yPos by companion id
  376.     if (id = 1) {
  377.         yPos = 350
  378.     }else if (id = 2) {
  379.         yPos = 414
  380.     }else if (id = 3) {
  381.         yPos = 478
  382.     }
  383.     ; Make sure Crew Management window is open
  384.     crewManageToggle("on")
  385.     ; check companion
  386.     PixelGetColor, color, xPos, yPos ; crew management companion [X] ("cancel current task")
  387.     ; Make sure Crew Management window is closed
  388.     crewManageToggle("off")
  389.     ; check if mission is active
  390.     if (id = 1 AND color="0xC0A669") {
  391.         return true
  392.     }else if (id = 2 AND color="0xD5BD83") {
  393.         return true
  394.     }else if (id = 3 AND color="0xDDC184") {
  395.         return true
  396.     }else{
  397.         return false
  398.     }
  399. }
  400.  
  401. ; Checks for pending reward windows (quest, end of space combat mission,
  402. ; tradeskill completion, tradeskill failure, etc). If it detects one on the
  403. ; left or right side of the screen it will close them.
  404.  
  405. hasMissionComplete() {
  406.     Loop {
  407.         ; Attempt to open pending data in case it's closed
  408.         MouseClick, left, 964, 37 ; Pending Rewards
  409.         Sleep, 1000
  410.         ; Grab pixel color magic
  411.         PixelGetColor, color_left, 207, 401
  412.         PixelGetColor, color_right, 819, 400
  413.         ; Check if there is a pending reward on the left
  414.         if (color_right="0x000000") {
  415.             ; Click the accept button for rewards
  416.             MouseClick, left, 933, 573 ; Accept reward
  417.             Sleep, 1000
  418.             ; Click the accept button for failures (just in case)
  419.             MouseClick, left, 933, 536 ; Accept reward
  420.             Sleep, 1000
  421.             continue
  422.         }
  423.         ; Check if there is a pending reward on the right
  424.         if (color_left="0x000000") {
  425.             ; Click the accept button for rewards
  426.             MouseClick, left, 227, 580 ; Accept reward
  427.             Sleep, 1000
  428.             ; Click the accept button for failures (just in case)
  429.             MouseClick, left, 227, 543 ; Accept reward
  430.             Sleep, 1000
  431.             continue
  432.         }
  433.         break
  434.     }
  435. }
  436.  
  437. ;--------------------------------------------------
  438. ; Spacebot Functions
  439. ;--------------------------------------------------
  440.  
  441. ; Handles the process for the space combat bot
  442.  
  443. spaceHandler() {
  444.     global
  445.     ; set the play status
  446.     inPlay:=1
  447.     ; start the combat mission
  448.     startMissionBot(1)
  449.     ; leave the mission
  450.     hasMissionComplete()
  451.     ; fix the camera after you get out
  452.     fixCamera()
  453. }
  454.  
  455. ; Moves you out of your command chair in order
  456. ; to enable bot to loop space missions
  457.  
  458. fixCamera() {
  459.     ; Send "W" key to move out of chair
  460.     SendInput, {w}
  461.     Sleep, 1000
  462.     ; Right click the chair
  463.     ; MouseClick, left,  519,  528
  464.     ; Sleep, 1000
  465. }
  466.  
  467. ; Right clicks the galaxy map or chair
  468. ; to open the galaxy map. See data.txt for
  469. ; more information.
  470.  
  471. openGalaxyMap() {
  472.     ; MouseClick, right,  502,  444
  473.     ; Sleep, 2000
  474.     MouseClick, right,  519,  528
  475.     Sleep, 2000
  476. }
  477.  
  478. ; Opens the appropriate galaxy from the
  479. ; galaxy map based on specificed mission or
  480. ; galaxy id. See data.txt for more information.
  481.  
  482. openGalaxy(id) {
  483.     ; Hutt Space
  484.     if (id = 1) {
  485.         MouseClick, left,  701,  352
  486.         Sleep, 2000
  487.         MouseClick, left,  466,  336
  488.         Sleep, 2000
  489.     }
  490. }
  491.  
  492. ; Starts the mission from the galaxy map
  493. ; if in the correct galaxy. Make sure it is
  494. ; called after openGalaxy(). See data.txt for
  495. ; more information.
  496.  
  497. openMission(id) {
  498.     ; Saluecami Fleet Action
  499.     if (id = 1) {
  500.         ; open the missions galaxy
  501.         openGalaxy(1)
  502.         ; open the mission
  503.         MouseClick, left,  863,  669
  504.         Sleep, 2000
  505.         MouseClick, left,  480,  441
  506.         Sleep, 2000
  507.     }
  508. }
  509.  
  510. ; Start running the .torbot script for the
  511. ; specified mission id
  512.  
  513. startMissionBot(id) {
  514.     ; start the bot
  515.     ; script = spacecombat%id%
  516.     script = mission%id%
  517.     ttHandler("Started %script%.torbot", 1000)
  518.     runBot(script)
  519. }
  520.  
  521. ; begin the main bot that handles space combat
  522. ; and tradeskills
  523.  
  524. startBot() {
  525.     global
  526.     ; Make SWTOR the active window
  527.     WinWait, Star Wars: The Old Republic,
  528.     IfWinNotActive, Star Wars: The Old Republic, , WinActivate, Star Wars: The Old Republic,
  529.     WinWaitActive, Star Wars: The Old Republic,
  530.     ; loop space missions
  531.     ; tradeskills inbetween missions if enabled
  532.     if(spaceEnabled) {
  533.         Loop %runCount% {
  534.             openGalaxyMap() ; open the galaxy map
  535.             openMission(missionId) ; open the mission's galaxy and mission
  536.             ; loop until we detect mission start
  537.             Loop {
  538.                 PixelGetColor, color, 1004, 757
  539.                 if(color = "0x084584") {
  540.                     ; are we going to record?
  541.                     if(inRecord = 1) {
  542.                         inRecord:=2 ; set the status to recording
  543.                         recordBot() ; start the recording
  544.                     ; start the space combat mission handler
  545.                     }else if(inRecord=0 AND inPlay=0) {
  546.                         spaceHandler()
  547.                     }
  548.                 }
  549.             }
  550.             ; run tradeskills after the mission
  551.             if(tradeskillEnabled) {
  552.                 tradeskillHandler()
  553.             }
  554.         }
  555.     }
  556.     ; space disabled and tradeskills enabled
  557.     ; loop tradeskills checking every 30 seconds
  558.     if(spaceEnabled = false AND tradeskillEnabled = true) {
  559.         Loop {
  560.             tradeskillHandler()
  561.             Sleep 30000
  562.         }
  563.     }
  564. }
  565.  
  566. ttHandler(msg, timer=2000) {
  567.     ToolTip, %msg%
  568.     SetTimer, RemoveToolTip, %timer%
  569. }
  570.  
  571. ;--------------------------------------------------
  572. ; Timers
  573. ;--------------------------------------------------
  574.  
  575. ; timer for removing tooltips
  576. RemoveToolTip:
  577.     SetTimer, RemoveToolTip, Off
  578.     ToolTip
  579. return
  580.  
  581. ; timer for mouse movement recording
  582. RecordMouseKey:
  583.     TimeMouseMove_Old := TimeMouseMove
  584.     MouseData := GetMouseMove(TimeMouseMove_Old)
  585.     if (MouseData_old = MouseData) {
  586.         return
  587.     }
  588.     MouseData_old := MouseData
  589.     RecordCount++
  590.     MouseData_%RecordCount% := MouseData "|" TimeMouseMove_Old - TimeMouseMove
  591.     TimeMouseMove := A_TickCount
  592. return
  593.  
  594. ;--------------------------------------------------
  595. ; Key Binds
  596. ;--------------------------------------------------
  597.  
  598. ; Kill the bot
  599.  
  600. Numpad0::
  601.     ExitApp
  602. return
  603.  
  604. ; Start the bot
  605.  
  606. Numpad1::
  607.     startBot()
  608. return
  609.  
  610. ; Start new recording. Press this before
  611. ; you enter the space mission using Numpad1.
  612. ; It will begin recording as soon as the mission starts.
  613.  
  614. Numpad4::
  615.     ; Make sure it is not running a torbot script already
  616.     if(inPlay = 1) {
  617.         ttHandler("Recording disabled during torbot scripts", 1000)
  618.         return
  619.     }
  620.     ; Make sure it is not currently recording
  621.     if(inRecord = 0) {
  622.         ttHandler("Recording has been started `nWaiting for space mission to load", 5000)
  623.         inRecord:=1 ; set state to recording
  624.     }
  625. return
  626.  
  627. ; Saves the bot manually. Normally it saves the
  628. ; bot recording automatically.
  629.  
  630. Numpad6::
  631.     saveRecording() ;
  632. return
  633.  
  634. ; Get x/y and color at mouse position
  635.  
  636. Numpad7::
  637.     MouseGetPos, xPos, yPos
  638.     PixelGetColor, color, xPos, yPos
  639.     MsgBox %color% at %xPos%, %yPos%
  640. return
  641.  
  642. ; Get color at specific x,y pos
  643.  
  644. Numpad8::
  645.     PixelGetColor, color, 693, 263
  646.     MsgBox %color%
  647. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement