Advertisement
Guest User

roblox tower defense simulator bot

a guest
Feb 19th, 2022
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 7.00 KB | None | 0 0
  1. #include <ScreenCapture.au3>
  2. #include <File.au3>
  3.  
  4. TitleMatch('winter_stronghold.png')
  5.  
  6. global $map = 0     ;name of current map
  7. global $ini = @scriptdir & '\data.ini'
  8. global $tx = 0
  9. global $ty = 0
  10. global $skips = 0
  11.  
  12. sleep(4000)
  13. Note('bot started')
  14. while 1
  15.     Init()
  16.     ClaimReward()
  17.     WalkToGame(Orient())
  18.     if  IdentifyMap() then
  19.         Sleep(40000)
  20.         PlayGame()
  21.     else
  22.         Reset()
  23.     endif
  24. wend
  25.  
  26. func Init()
  27.     $map = 0        ;name of current map
  28.     $ini = @scriptdir & '\data.ini'
  29.     $tx = 0
  30.     $ty = 0
  31.     $skips = 0
  32. endfunc
  33.  
  34. func ClaimReward()
  35.     sleep(500)
  36.     mouseclick('left', 960, 660)
  37.     sleep(500)
  38. endfunc
  39.  
  40. func Orient()
  41.     local $left  = 1000, $top = 20, $right = 1400, $bottom = 120, $color = 0xFFE469
  42.     PixelSearch($left, $top, $right, $bottom, $color, 10)
  43.     if not @error then return 1
  44.  
  45.     local $left  = 120, $top = 0, $right = 700, $bottom = 140, $color = 0xFFE469
  46.     PixelSearch($left, $top, $right, $bottom, $color, 10)
  47.     if not @error then return 2
  48.  
  49.     local $left  = 1640, $top = 150, $right = 1800, $bottom = 330, $color = 0x42F257
  50.     PixelSearch($left, $top, $right, $bottom, $color, 10)
  51.     if not @error then return 3
  52.  
  53.     local $left  = 850, $top = 200, $right = 1130, $bottom = 330, $color = 0x42F257
  54.     PixelSearch($left, $top, $right, $bottom, $color, 10)
  55.     if not @error then return 4
  56.  
  57.     local $left  = 1120, $top = 200, $right = 1440, $bottom = 420, $color = 0xF2C2F1
  58.     PixelSearch($left, $top, $right, $bottom, $color, 10)
  59.     if not @error then return 5
  60.  
  61.     local $left  = 570, $top = 200, $right = 780, $bottom = 430, $color = 0xF2C2F1
  62.     PixelSearch($left, $top, $right, $bottom, $color, 10)
  63.     if not @error then return 6
  64.  
  65.     local $left  = 500, $top = 0, $right = 890, $bottom = 140, $color = 0xC0FEBE
  66.     PixelSearch($left, $top, $right, $bottom, $color, 5)
  67.     if not @error then return 7
  68.  
  69.     local $left  = 500, $top = 0, $right = 890, $bottom = 140, $color = 0xC0FEBE
  70.     PixelSearch($left, $top, $right, $bottom, $color, 5)
  71.     if not @error then return 8
  72.  
  73.     local $left  = 500, $top = 0, $right = 890, $bottom = 140, $color = 0x547DBD
  74.     PixelSearch($left, $top, $right, $bottom, $color, 7)
  75.     if not @error then return 7
  76.  
  77.     local $left  = 570, $top = 392, $right = 605, $bottom = 430, $color = 0x66464A
  78.     PixelSearch($left, $top, $right, $bottom, $color, 7)
  79.     if not @error then return 8
  80.  
  81.     return 0
  82. endfunc
  83.  
  84. func WalkToGame($direction)
  85.     Note('finding a lobby')
  86.     switch $direction
  87.         case 1
  88.             ; walk D
  89.             send('{d down}')
  90.             sleep(8250)
  91.             send('{d up}')
  92.  
  93.             ;walk S
  94.             send('{s down}')
  95.             sleep(1000)
  96.             send('{s up}')
  97.  
  98.         case 2
  99.             ; walk WD
  100.             send('{w down}')
  101.             send('{d down}')
  102.             sleep(7250)
  103.             ; walk D
  104.             send('{w up}')
  105.             sleep(1000)
  106.             send('{d up}')
  107.  
  108.         case 3
  109.             ;walk A
  110.             send('{a down}')
  111.             sleep(1000)
  112.             send('{a up}')
  113.  
  114.             ;walk W
  115.             send('{w down}')
  116.             sleep(7500)
  117.             send('{w up}')
  118.  
  119.             ;walk D
  120.             send('{d down}')
  121.             sleep(1250)
  122.             send('{d up}')
  123.  
  124.         case 4
  125.             ;walk s
  126.             send('{s down}')
  127.             sleep(3000)
  128.             send('{s up}')
  129.  
  130.             ;walk wa
  131.             send('{w down}')
  132.             send('{a down}')
  133.             sleep(9750)
  134.             send('{w up}')
  135.             send('{a up}')
  136.  
  137.             ;walk wd
  138.             send('{w down}')
  139.             send('{d down}')
  140.             sleep(1500)
  141.             send('{d up}')
  142.             send('{w up}')
  143.  
  144.         case 5
  145.             ;walk s
  146.             send('{s down}')
  147.             sleep(2200)
  148.             send('{s up}')
  149.  
  150.             ;walk a
  151.             send('{a down}')
  152.             sleep(8300)
  153.             send('{a up}')
  154.  
  155.             ;walk w
  156.             send('{w down}')
  157.             sleep(1100)
  158.             send('{w up}')
  159.  
  160.         case 6
  161.             ;walk s
  162.             send('{s down}')
  163.             sleep(3500)
  164.             send('{s up}')
  165.  
  166.             ;walk as
  167.             send('{a down}')
  168.             send('{s down}')
  169.             sleep(6500)
  170.             send('{a up}')
  171.             send('{s up}')
  172.  
  173.             ;walk aw
  174.             send('{a down}')
  175.             send('{w down}')
  176.             sleep(1700)
  177.             send('{a up}')
  178.             send('{w up}')
  179.  
  180.         case 7
  181.             ;walk SD
  182.             send('{s down}')
  183.             send('{d down}')
  184.             sleep(3500)
  185.             send('{d up}')
  186.  
  187.             ;walk S
  188.             sleep(6750)
  189.             send('{s up}')
  190.  
  191.             ;walk A
  192.             send('{a down}')
  193.             sleep(2500)
  194.             send('{a up}')
  195.  
  196.         case 8
  197.             ;walk D
  198.             send('{d down}')
  199.             sleep(2250)
  200.  
  201.             ;walk SD
  202.             send('{s down}')
  203.             sleep(7250)
  204.             send('{d up}')
  205.  
  206.             ;walk AS
  207.             send('{a down}')
  208.             sleep(2500)
  209.             send('{a up}')
  210.             send('{s up}')
  211.  
  212.     endswitch
  213.  
  214.     sleep(500)
  215.  
  216. endfunc
  217.  
  218. func Reset()
  219.     send("{ESC}")
  220.     sleep(1000)
  221.     send("{r}")
  222.     sleep(500)
  223.     send("{ENTER}")
  224.     sleep(7000)
  225. endfunc
  226.  
  227. func IdentifyMap()
  228.     Local $bitmap = _ScreenCapture_Capture(@scriptdir & "\title.png", 715, 749, 1160, 786)
  229.     local $size = FileGetSize(@scriptdir & "\title.png")
  230.     local $path = @scriptdir & "\titles"
  231.     local $titles = _FileListToArray($path)
  232.     local $sizes[0]
  233.  
  234.     ;iterate through titles to find a match
  235.     For $i = 1 To $titles[0] step 1
  236.         if TitleMatch($path & "\" & $titles[$i]) then
  237.             $map = stringtrimright($titles[$i], 4)
  238.             Note('map: ' & $map)
  239.             return true
  240.         endif
  241.     Next
  242.  
  243.     return false
  244.  
  245. endfunc
  246.  
  247.  
  248. func TitleMatch($imagepath)
  249.     $pixels = 16948
  250.     $command = 'magick compare -fuzz 10%% -metric AE title.png ' & $imagepath & ' null: 2>info.txt'
  251.     runwait(@ComSpec & " /c " & $command, "", @SW_HIDE)
  252.  
  253.     $changed = Int(filereadline('info.txt'))
  254.     $difference = $changed / $pixels
  255.  
  256.     if $difference < 0.25 then
  257.         return true
  258.     else
  259.         return false
  260.     endif
  261.  
  262. endfunc
  263.  
  264.  
  265. func PlayGame()
  266.     SelectDifficulty()
  267.     PlaceTower()
  268.  
  269.     While StillAlive()
  270.         SkipLevel()
  271.         UpgradeTower()
  272.     wend
  273.  
  274.     LeaveGame()
  275.     RejoinServer()
  276.  
  277. endfunc
  278.  
  279. func SelectDifficulty()
  280.     MouseClick("left", 960, 580)
  281.     Note("selected difficulty")
  282.     sleep(15000)
  283. endfunc
  284.  
  285. func PlaceTower()
  286.     $ini = @scriptdir & '\data.ini'
  287.     $tx = IniRead($ini, $map, 'tx', 0)
  288.     $ty = IniRead($ini, $map, 'ty', 0)
  289.  
  290.     if $tx = 0 and $ty = 0 then
  291.         Note('something messed up')
  292.         exit
  293.     endif
  294.  
  295.     if $map = 'grass_isles' then
  296.         ;walk S for 2 seconds
  297.         send('{s down}')
  298.         sleep(2000)
  299.         send('{s up}')
  300.     endif
  301.  
  302.  
  303.     Send('{1}')
  304.     sleep(2000)
  305.     Note("placed tower at " & $tx & "," & $ty)
  306.     MouseClick("left", $tx, $ty)
  307.     sleep(10000)
  308.  
  309. endfunc
  310.  
  311. func StillAlive()
  312.     ;check for red button
  313.     local $left = 885, $top = 715, $right = 1035, $bottom = 750, $color = 0xFF0000
  314.     PixelSearch($left, $top, $right, $bottom, $color, 2)
  315.     if not @error then
  316.         Note("defeated")
  317.         return false
  318.     else
  319.         return true
  320.     endif
  321. endfunc
  322.  
  323. func SkipLevel()
  324.     ;check for green yes button
  325.     local $left = 850, $top = 200, $right = 940, $bottom = 230, $color = 0x00FF00
  326.     PixelSearch($left, $top, $right, $bottom, $color, 2)
  327.     if not @error then
  328.         mouseclick("left", 900, 215)
  329.         $skips += 1
  330.         Note('skipped level')
  331.         sleep(1000)
  332.         MouseClick("left", $tx, $ty)
  333.     endif
  334.  
  335. endfunc
  336.  
  337. func UpgradeTower()
  338.     MouseClick("left", $tx + 90, $ty - 95)
  339.     sleep(20000)
  340. endfunc
  341.  
  342.  
  343. func LeaveGame()
  344.     sleep(500)
  345.     send("{ESC}")
  346.     sleep(500)
  347.     send("{l}")
  348.     sleep(500)
  349.     send("{ENTER}")
  350.     Note('leaving match')
  351.     sleep(10000)
  352. endfunc
  353.  
  354. func RejoinServer()
  355.     local $x =
  356.     local $y =
  357.     Note('rejoining private server')
  358.     mouseclick("left", $x, $y)
  359.     sleep(20000)
  360. endfunc
  361.  
  362.  
  363. func Note($entry)
  364.     $log = FileOpen(@scriptdir & '\log.txt', 1)
  365.     $timestamp = @HOUR & ":" & @MIN & ":" & @SEC
  366.     FileWriteLine($log, $entry)
  367.     fileclose($log)
  368. endfunc
  369.  
  370.  
  371.  
  372.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement