Guide Automating Fishing

Vent

Terrarian
So, fishing is tedious and hateful. I have a script for that. This uses Autohotkey.

First, some important notes:

- This script is a development of a script written by the glow. His original can be found in a thread here. Many parts of the code below are taken directly from his. He should receive the lion's share of credit for the final product here.
- This script is designed for 1080p resolution. If you play on a different resolution, you'll have to tweak some of the X, Y coordinates in the code.
- Because of (I believe) some wonkiness with DirectX, Windows Aero doesn't play well with this script when the game is fullscreened. In order for the script to work, Windows has to be in "Windows Classic" mode. Right click your desktop and hit Personalize to bring this up. This is on Windows 7. I'm not sure how the script interacts with Windows 8 or 10.
- The script doesn't like blocks or other items (golden chests, demon torches, etc.) that change the color of surrounding pixels. Avoid them in your fishing build.

Second, some instructions on usage:

- Find a fishing area where the water is directly below you (use platforms or UFO or whatever).
- Place your cursor anywhere near the water line, though slightly over the waterline works best. Horizontal position of the cursor doesn't matter.
- This script will automatically rebuff, so don't have any potions in your inventory except for fishing and crate potions.
- Have lots of bait (thousands is good), load up +fishing gear, pull up your fishing rod the inventory, and then hit F2.
- Turn off your monitor, go to sleep, and wake up to thousands of fish, crates, and accessories.

Using this script I had about 2500 crates ready for hardmode without any manual fishing to speak of.

Code:
  #NoEnv
  #MaxHotkeysPerInterval 9999
  #MaxThreadsPerHotkey 2
  SetTitleMatchMode 2

  ; Terraria initialize
  global c_delay := 30
  global breakLoop := 0

  *~Esc::breakLoop = 1



#IfWinActive ahk_exe Terraria.exe

  ;*** SUSPEND HOTKEY
  ;*
  *Pause::
    Suspend
    Pause
  return



  ;*** CHAT SUSPENDS ALL HOTKEYS
  ;*
  ;*   This will occasionally glitch, fix by using the general Suspend key above.
  *~Enter::
    Suspend
    Pause
  return



  ;*** FUNCTION: mClick
  ;*
  mClick(f_delay:=0, x:="", y:="") {
    Send {Click down %x%, %y%}
    Sleep %c_delay%
    Send {Click up}
    Sleep %c_delay%
    Sleep %f_delay%
  }



  ;*** FUNCTION: keyClick
  ;*
  keyClick(f_delay, key) {
    Send {%key% down}
    Sleep %c_delay%
    Send {%key% up}
    Sleep %c_delay%
    Sleep %f_delay%
  }



  ;*** AUTOMATIC FISHING
  ;*
  ;*   Windows desktop settings must be at "Windows Classic"
  F2::

    MouseGetPos, WaterX, WaterY                   ; Get vertical position of cursor (should point just above water line)

    Loop {

      if (breakLoop = 1)
        break

      mClick(2200, 970, 900)                             ; Cast the line & wait for bob to settle

      if (breakLoop = 1)
        break

      PixelGetColor, colorA, 969, %WaterY%    ; Get the color of the bob
      colorB1 := colorA                                      ; Set the variables which will monitor for changed color of the bob
      colorB2 := colorA
      colorB3 := colorA

      Loop, 100 {                                                ; Wait for the bob to move
        if (breakLoop = 1)
          break
   
        PixelGetColor, colorB1, 969, %WaterY%
          Sleep 10
        PixelGetColor, colorB2, 969, %WaterY%
          Sleep 10
        PixelGetColor, colorB3, 969, %WaterY%
          Sleep 10
   
        if (compare(colorA, colorB1) > 5) {
          if (compare(colorA, colorB2) > 5) {
            if (compare(colorA, colorB3) > 5) {   
              Sleep 100
              mClick(0, 970, 900)
              break
            }
          }
        }   
      }

      keyClick(0, "b")                                           ; Renew buffs

    }

    breakLoop = 0
    return



  compare(c1, c2) {
    rdiff := Abs((c1 >> 16) & 0xFF - (c2 >> 16) & 0xFF)
    gdiff := Abs((c1 >> 8) & 0xFF - (c2 >> 8) & 0xFF)
    bdiff := Abs(c1 & 0xFF - c2 & 0xFF)

    return rdiff + gdiff + bdiff
  }



#IfWinActive

Some unhelpful pics. Credit to Papabear for his fishing arena. The original design can be found here.

Line up the cursor and press F2:

62F80FC8310609E38157EF6E2DB6DEB40A48336E


Win! Now go to sleep:

663B60AD7DF0026718F56B461EF1B0B0F755CCC6


Let me know if you find any bugs!

Edit: Added the compare function, which I had forgotten about.
Later edits: Bugs and tweaks.
 
Last edited:
testing it out :D
didnt read anything on your reminders so this happened on win10
BakiEZu.png

youre supposed to copy paste everything right?
 
Last edited:
Looks like the code for compare() is missing. I'm pretty sure that's not a built-in function.

Ah, here it is (taken from the thread Vent linked to)
Code:
compare(c1, c2) {
    rdiff := Abs((c1 >> 16) & 0xFF - (c2 >> 16) & 0xFF)
    gdiff := Abs((c1 >> 8) & 0xFF - (c2 >> 8) & 0xFF)
    bdiff := Abs(c1 & 0xFF - c2 & 0xFF)

    return rdiff + gdiff + bdiff
}

Just add that to the end and it should work. Haven't tested it though.
 
Wow! I like that way you customized the fishing complex!

2500 crates... that must have taken hours to open them all. For the last three playthroughs I've had about 1/10 of that and it seems like it takes forever to open them all and sell what is duplicated.

Fishing can be kind of tedious, I just might try that script.
 
Thatgamer & ManaUser, thanks for catching that! I edited my post to include the compare function. I don't know how I missed that.

Papabear, I'm glad you like it! I was so impressed with your post - very clever. It wasn't too bad opening the 2500 crates. I basically just sat there spamming the crates and had someone else running from me to the chests with autostack. We had to take a lot of breaks to sell stuff though. It was completely overkill, but it was also hilarious.

Some good uses for this script:

- Grab a fishing quest, drop to Papabear's fishing arena, start the script, go get coffee, come back and turn in the quest.
- On a multiplayer server, where some items are very limited (especially if more than two players are on the server), use it for biome crates for the shield & horseshoe. Also the aglet (from wood crates, about 1 every 200 crates or so), anklet of the wind (about 1 in every 30 jungle crates), tsunami in a bottle, and balloon pufferfish.
 
I found the script really, really slow as there was a lot of flailing about and waiting between successful catches. To fix this, I added a
Code:
SetMouseDelay 50
near the top of the script and now it works (almost) like clockwork. After I got that sorted out, I was able to fish up over 600 crates in a few hours but at the cost of about 800 Grubbies. Those 600 crates are a bit of overkill as only 250 or so is good enough to almost insure that you will be getting enough hardmode ore to make Titanium armor and everything else you might need to get by without breaking a single Demon Altar.
Now, I wish there was an easy way to get bait. I lucked out this time by finding some Flower Boots but even with those there is some tedium in getting that much bait. Oh, well. :merchantsad:
 
I found the script really, really slow as there was a lot of flailing about and waiting between successful catches. To fix this, I added a
Code:
SetMouseDelay 50
near the top of the script and now it works (almost) like clockwork. After I got that sorted out, I was able to fish up over 600 crates in a few hours but at the cost of about 800 Grubbies. Those 600 crates are a bit of overkill as only 250 or so is good enough to almost insure that you will be getting enough hardmode ore to make Titanium armor and everything else you might need to get by without breaking a single Demon Altar.
Now, I wish there was an easy way to get bait. I lucked out this time by finding some Flower Boots but even with those there is some tedium in getting that much bait. Oh, well. :merchantsad:

If you have flower boots, you just make a little patch of jungle and hold down mouse1 with the golden bug net. Add this to your AutoHotkey:

Code:
  ;*** HOLD DOWN MOUSE1
  ;*
  z::Send % "{Click " . ( GetKeyState("LButton") ? "Up}" : "Down}" )

066988D1AA7F25E0DAFCF44754A0679053F6BDBC


The above picture is from this Steam guide.

Edit: Papabear! I forgot the c_delay variable in the script. This is what happens when you try to pick out just certain parts of a longer script. I've added the variable to the script in the OP. =/

The script should work fine now without the "flailing" about. Kudos on finding the mousedelay command.
 
I couldn't get it to work. I guess I don't need crates anyway, I've got full Mythril armour and that's all I need to defeat any mech boss
 
Necro!

Normally I'd consider a script like this cheating... but myself and others have made Skyblock maps. Fishing for all your heart crystals gets pretty brutal.

I have a 4k monitor. Most scripts including the one in this post use fixed positions to check the bobber, which breaks different resolutions or window mode. I also noticed the the c_delay was too short and the bobber check was too close to the cursor position. I made a toggle key for the autobuff function and turned it off by default. Lastly, I tried to make the code a bit easier to read.

Oh, and this isn't different from above version, but this should work just fine for most texture packs or mod fishing rods.

P.S.: Shameless plug for Brutal Skyblock on Curseforge (everything) and Steam (for classic difficulty only).

Edit: after sleeping on it, I realized the order of operations wasn't ideal and there were some pointless sleeps that needlessly gave the script a more "human" seeming reaction time. Should be more optimal now.

Edit: came back to refine numbers after a long time using and sharing it. Not perfect, but pretty good.

C#:
/*        ***INSTRUCTIONS***

1. Install AutoHotkey https://www.autohotkey.com/
2. If copy/pasting this script, save it as a txt file, then change the extension to .ahk
3. Run this script
4. Play Terraria
5. Place your cursor JUST above the water line, but below where the top of the bobber sprite will be.  Works best when fishing straight beneath your character.
6.  Press F2 to start the script.  It will do your first cast for you.

        ***Keys***
F2: Records the cursor location as the spot to "check" for bobber movement and starts auto-fishing.  Press again to record adjust the location.  This check makes the script work at all screen resolutions, windowed mode etc.

F3: Toggles auto-buff (uses the "b" hotkey).  Make sure you only have fishing related potions in your inventory before enabling.  Default is off.

Esc: stops autofishing

Pause/Enter: pauses and resumes the script

*/

#NoEnv
  #MaxHotkeysPerInterval 9999
  #MaxThreadsPerHotkey 2
  SetTitleMatchMode 2

  ;Terraria initialize
  global c_delay := 50                            ;Click delay variable.  Increase for laggy computers
  global breakLoop := 0

  *~Esc::breakLoop = 1


#IfWinActive ahk_exe Terraria.exe

  ;PAUSE SCRIPT HOTKEY
  *Pause::
    Suspend
    Pause
  return


  ;ENTERING GAME CHAT ALSO PAUSES SCRIPT        This will occasionally glitch, fix by using the general Pause key above.
  *~Enter::
    Suspend
    Pause
  return


  ;HOTKEY TO ENABLE AUTO POTION CHUGGING
  buff := 0
  *F3::
    buff := !buff
  return

  ;FUNCTION: mClick                                Used for clicking the mouse to cast rod
  mClick(f_delay:=0, x:="", y:="") {
    Send {Click down %x%, %y%}
    Sleep %c_delay%
    Send {Click up}
    Sleep %c_delay%
    Sleep %f_delay%
  }



  ;FUNCTION: keyClick                            Used for clicking the "b" key to chug buff potions when they run out
  keyClick(f_delay, key) {
    Send {%key% down}
    Sleep %c_delay%
    Send {%key% up}
    Sleep %c_delay%
    Sleep %f_delay%
  }



  ;AUTOMATIC FISHING
  F2::

    MouseGetPos, WaterX, WaterY                    ;Get position of cursor (should point just above water line)
 
    WaterX2 := WaterX - 2                        ;Space 2 pixels above cursor position AKA the bobber

    Loop {

      if (breakLoop = 1)
        break

      mClick(2200, %WaterX%, %WaterY%)            ; Cast the line & wait for bob to settle

      if (buff = 1)                                ; Renew buffs if enabled
        keyClick(0, "b")

      if (breakLoop = 1)
        break

      PixelGetColor, colorA, %WaterX2%, %WaterY%    ; Get the color of the bob
      colorB1 := colorA                                ; Set the variables to monitor for changed color of the bob
      colorB2 := colorA
      colorB3 := colorA

      Loop, 250 {                                    ; Wait for the bob to move, else click again
        if (breakLoop = 1)
          break
 
        PixelGetColor, colorB1, %WaterX2%, %WaterY%
          Sleep 10
        PixelGetColor, colorB2, %WaterX2%, %WaterY%
          Sleep 10
        PixelGetColor, colorB3, %WaterX2%, %WaterY%
 
        if (compare(colorA, colorB1) > 5) {
          if (compare(colorA, colorB2) > 5) {
            if (compare(colorA, colorB3) > 5) {
              mClick(70, %WaterX%, %WaterY%)
              break
            }
          }
        }
      }
    }

    breakLoop = 0
    return


  compare(c1, c2) {
    rdiff := Abs((c1 >> 16) & 0xFF - (c2 >> 16) & 0xFF)
    gdiff := Abs((c1 >> 8) & 0xFF - (c2 >> 8) & 0xFF)
    bdiff := Abs(c1 & 0xFF - c2 & 0xFF)

    return rdiff + gdiff + bdiff
  }

#IfWinActive
 
Last edited:
Hmm, using the audio is an interesting detection method. Seems like it would have a lot of false positives, but it's more noob friendly than this script's requirement of lining up the cursor. I really like the built in timer function.

Haha thanks. It was originally used designed to be used for minecraft as a requested external fishing tool, but I was also asked to make one for Terraria. Simple GUI, basic tools, and little to no setup makes it great for noobies. By changing the sound in game and closing yourself off in the game to enemies exc, it's false positives are little to none. Reguardless I love to see others attempt this as well.
 
Hello! For any new people wanting to try this out, it still works like a charm. If you are using tmodloader and you see it does not work, what you have to do is go into the AHK file and edit it as a notepad. You then have to find where it says "terraria.exe" and change it to "dotnet.exe". Pictures attached. Enjoy!

Capture.PNG




Edit: Few bugs i have found as in most of the time it will not throw back out your bobber when you reel in a catch.
 
Last edited:
Hello! For any new people wanting to try this out, it still works like a charm. If you are using tmodloader and you see it does not work, what you have to do is go into the AHK file and edit it as a notepad. You then have to find where it says "terraria.exe" and change it to "dotnet.exe". Pictures attached. Enjoy!

View attachment 379075



Edit: Few bugs i have found as in most of the time it will not throw back out your bobber when you reel in a catch.
Good to know. Though unless you're playing multiplayer and can't convince the host to add any mod to reduce the fishing grind, it's not a great option then.
Have you tried the edited script I posted early here? Pretty sure I had most of the timing issues ironed out. I'm happy to dial it in more for working with different computers.
 
Back
Top Bottom