Farmer Against Potatoes Idle

Farmer Against Potatoes Idle

34 个评价
Whack-A-Potato Python Script (No-Setup, Fastest)
由 Triplesito 制作
Bot written in Python3 to auto-play the infamous Whack-A-Potato minigame, clicks between 350-450 potatoes each game with 100% accuracy. It can work idle and will start a new game when it's ready.
3
4
2
   
奖励
收藏
已收藏
取消收藏
How it works - IMPORTANT
The code is already set up for 1920x1080 screen resolution, the game window must be maximized (not fullscreen), and the windows 10 taskbar must be at the bottom. Otherwise you will need to set the coordinates manually, it's explained very easily on the Manual Setup section.

Here is a video showing it in action:
Installing Python
Download:

The first thing you need to do is install Python, if you are not familiarized with it it's a very easy to use and versatile programming language that saves scripts in ".py" files that can be run through the command terminal (also known as "cmd"). The "cmd" can be opened by typing "cmd" in the Windows search bar and pressing enter.

Download Python from the official website https://www.python.org/downloads/

During the installation process make sure to select "Add python 3.x to PATH", when finished restart the computer and verify the installation by opening the "cmd" (by typing it in the windows search bar), typing "python" in the command line and pressing enter, if you can see three ">>>", the installation has been successful, now exit python by typing "quit()" or just close and open the console, you should no longer see the ">>>".

The last thing you need to do is install the module "PyAutoGUI" by running the command:
pip install pyautogui
If you get any errors while doing the module installation, follow the instructions below.

Optional but strongly recommended:

If not, it means the PATH hasn't been added correctly, this is optional but it's a time saver, without PATH you have to write the whole file address to run the script like: "C:/Users/"YourName"/Desktop/script_name.py", instead of just: "script_name.py". Here is a guide on how to do it on any OS: https://realpython.com/add-python-to-path/

If you want to keep the script file "script_name.py" in your desktop (or any other folder) instead on the "cmd" default folder, check this guide on how to change "cmd" default folder, and set it to your desktop (C:\Users\"YourName"\Desktop) or wherever you want: https://www.nucleiotechnologies.com/how-to-change-the-default-directory-of-command-prompt-in-windows-10/

If you installed Python and PyAutoGUI, now you are ready to copy and paste the script.
The script (copy-paste this)
Once you have finished installing python, you have to create a new file in your desktop and call it something like "whack.py".

Open it with the notepad and paste this in:
import pyautogui as pg import multiprocessing as mp import time # Variables to modify # sceneScreenshotCornerX = 350 sceneScreenshotCornerY = 210 sceneScreenshotWidth = 650 sceneScreenshotHeight = 640 leftBorderToToilet = 69 topBorderToToilet = 135 toiletToToiletX = 130 toiletToToiletY = 213 startScreenshotCornerX = 900 startScreenshotCornerY = 100 startButtonX = 700 startButtonY = 1000 gameFPS = 60 # Set this number to the FPS your game runs at gameplaySeconds = 60 # If you didn't fully upgrade the Whack-A-Potato game time, set this to how many seconds your game lasts # ------------------- # def launchAutoclicker(): time.sleep(3) while True: # Get toilets screenshot and check for potatoes screenshot = pg.screenshot(region=(sceneScreenshotCornerX, sceneScreenshotCornerY, sceneScreenshotWidth, sceneScreenshotHeight)) #screenshot.save("screenshot1.png") # If you want to see the screenshot for testing remove the first "#" on this line (saving the screenshot takes up time and will kill the autoclicking) for y in range(topBorderToToilet, sceneScreenshotHeight, toiletToToiletY): # 3 rows for x in range(leftBorderToToilet, sceneScreenshotWidth, toiletToToiletX): # 5 columns if screenshot.getpixel((x,y))[0] > 200: # If brown or golden, click pg.click(x + sceneScreenshotCornerX,y + sceneScreenshotCornerY) time.sleep(1 / gameFPS) def main(): while True: # Checks if game can start screenshot = pg.screenshot(region=(startScreenshotCornerX, startScreenshotCornerY, 50, 1)) #screenshot.save("screenshot2.png") # If you want to see the screenshot for testing remove the first "#" on this line (saving the screenshot takes up time and will kill the autoclicking) for startX in range(0, 50): # If the game can start, launch launchAutoclicker() independently if screenshot.getpixel((startX, 0))[2] > 200: clickerProcess = mp.Process(target=launchAutoclicker) clickerProcess.start() pg.click(startButtonX, startButtonY) time.sleep(gameplaySeconds + 5) clickerProcess.kill() break # Wait one second between checks (remove this if you want it to never stop checking, not recommended) time.sleep(1) ### START ### if __name__ == '__main__': main()

If you saved the file correctly now it should be a python file, indicated by the python logo, don't open it or the script would launch on your desktop, now check the section below, "How to use it".
How to use it
Once you have the script file on your desktop or wherever you want, open the "cmd", if you followed all the instructions above skip to "Launch the script".

If you didn't set the cmd's default folder to your desktop (explained above, on the optional section), you must navigate to it by typing the command:

cd C:\Users\"YourName"\Desktop

Now you are at your desktop's folder, seeing something like this:



Launch the script

To launch the script, you must have the Whack-A-Potato window and the "cmd" open, make the terminal tiny, place it anywhere on the right half of the screen, and write "whack.py", like in the image:


Now to launch it you just have to press Enter, but before you do, read below.

If the script doesn't click on the right places or seems to be working wrong, check the manual setup.

Closing the script and Emergency exit

To close python scripts, you have to click the "cmd" and press CTRL+C, or just close the terminal.

I didn't add any "exit" keys to the code because it would make it slower, if you want to stop the script in the middle of the clicking, just move your mouse around the screen, if the mouse touches a corner the script will stop clicking. After this, close the script as this only stops autoclicking for a minute.

Script is on, now what?

Now just let it work, it will detect when the game can be started, then press start, then play the game, and then it will be back to detecting when can it play again. Just remember to close it when you are finished by entering CTRL+C in the cmd.
Manual Setup
If the script doesn't work as it should, you may need to set the coordinates for the screen manually, this may take around 15 minutes, but it's definetly worth it.

First, you will need a "tool" for taking the coordinates. Make a new file named "coordinates.py", open it on the notepad and paste this:

import pyautogui pyautogui.displayMousePosition()

This will be used as a tool for collecting the coordinates needed for the manual setup, now open the file by double clicking it, you should see your mouse current coordinates on the terminal, use this to take and measure the coordinates on the image.

Once you have everything measured, replace the values in the code under the # Variables to modify # line.



Variables:

1. sceneScreenshotCornerX = Coordinate X of the top left corner of the main game screen
2. sceneScreenshotCornerY = Coordinate Y of the top left corner of the main game screen
3. sceneScreenshotWidth = Main game screen width in PIXELS
4. sceneScreenshotHeight = Main game screen height in PIXELS

5. leftBorderToToilet = Distance from left main game screen border to potato detection point in PIXELS
6. topBorderToToilet = Distance from top main game screen border to potato detection point in PIXELS

7. toiletToToiletX = Distance from the potato detection point on the first row/first column to the detection point on the first row/second column in PIXELS
8. toiletToToiletY = Distance from the potato detection point on the first row/first column to the detection point on the second row/first column in PIXELS

Here take any point in the red line at the right of the "9".
9. startScreenshotCornerX = Coordinate X of the point
9. startScreenshotCornerY = Coordinate Y of the point

Here take any point in the start button
10. startButtonX = Coordinate X of the point
10. startButtonY = Coordinate Y of the point

Look at the image if you are confused with any variable.

In depth:

With these coordinates you are going to set up a "main frame", this is the area of your screen that the script is mostly going to be working with.

The points 1 and 2 contain the coordinates of the top-left corner of this main frame, point 3 contains the width of the main frame, the distance in pixels from the left border to the right border, while point 4 contains the height of the main frame, which is the distance in pixels from the top border to the bottom border.

This sets up the main frame, like a box, and with the next coordinates we are going to divide the box in little boxes, making a grid.

For the points 5, 6, 7 and 8, we need to understand what a "potato detection point" is. The script works by looking at one pixel for every toilet, if that pixel contains the color of a good potato, it clicks right there. That pixel is the potato detection point.

Now that you know that, look at the picture, there is a red dot on the center of the first toilet, that is the potato detection point (PDP from now on). Point 5 is the distance in pixels from the PDP to the left side of the main frame, for example, if the PDP X coordinate is 500, and the main frame X coordinate is 450, the point 5 value would be 50 pixels, the distance between them, point 6 is the distance in pixels from the PDP to the top side of the main frame, we can take the same example, if the PDP Y coordinate is 300, and the main frame Y coordinate is 200, the point 6 value would be 100.

Points 7 and 8 measure the distance from the adjacent PDPs instead of the main frame borders. Point 7 contains the distance from the PDP we were working with, to the PDP of the toilet at the right side, and point 8 constains the distance from the PDP to the PDP of the toilet at the bottom of it.

To clarify point 9, there is a red line inside a green box right next to the "9" in the picture, you have to take any point in that red line. When the game is ready to start, in that area a white text shows up saying something like "The potatoes are ready!!!", that white text is what the script looks for to start the game.

Point 10 is just any coordinates inside the START button for the script to click.
Credits
If you have any problems or questions feel free to leave a comment and i will see if i can help.

The code and guide was made by Triplesito, if you liked this i encourage you to do the same, learn python and bot your games, it's the easiest thing you can imagine!!

Acknowledgments
Thanks to Goast for implementing a pause relative to the FPS after each click thus preventing the script from clicking too fast and breaking the combo.
99 条留言
giorgiobusoni 22 小时以前 
i tried setupping the coordinates, but it never sees the potatoes on the second row, don't know why
giorgiobusoni 23 小时以前 
I was able to run it but it does nothing. Does is work with game in windows mode, not full screen? Is there any read to go coordinate setup for a 4k screen?
pieks77 4 月 26 日 上午 6:49 
I manualy installed keyboard and ImageGrab modules. Works like a charm! Thanks for script,
Exxile 3 月 9 日 下午 3:15 
Followed all the instructions, got everything installed. When I run the whack.py script, it "starts" but doesn't actually do anything. I still retain full control of my mouse and can ctrl+C to stop the script, but the script itself doesn't seem to actually click anything
Yuri 2024 年 10 月 11 日 上午 5:29 
Thank you very much. You've saved me from a hundred restless nights.
korki 2024 年 9 月 28 日 上午 3:48 
I changed the Coords for a 2560x1440 Main Screen Resolution:

# Variables to modify #
sceneScreenshotCornerX = 445
sceneScreenshotCornerY = 275
sceneScreenshotWidth = 890
sceneScreenshotHeight = 865

leftBorderToToilet = 90
topBorderToToilet = 190

toiletToToiletX = 175
toiletToToiletY = 290

startScreenshotCornerX = 1100
startScreenshotCornerY = 110

startButtonX = 860
startButtonY = 1337
Moggosh [GER] 2024 年 9 月 24 日 上午 2:35 
year 2024 and we are not able to get this working for everybody... poor humanity, its not rocket science
jargonchipmunk 2024 年 9 月 16 日 下午 3:10 
File "C:\Users\jamdo\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\__init__.py", line 228, in _couldNotImportPyScreeze
raise PyAutoGUIException(
pyautogui.PyAutoGUIException: PyAutoGUI was unable to import pyscreeze. (This is likely because you're running a version of Python that Pillow (which pyscreeze depends on) doesn't support currently.) Please install this module to enable the function you tried to call.
dev.mohaa 2024 年 8 月 30 日 下午 9:33 
Worked, but always breaking the combo :/ Any suggestions?
MrLyrox 2024 年 8 月 24 日 下午 5:16 
hello les connaisseurs !! pensez-vous (si oui, comment) qu’il est possible d’ajouter un paragraphe qui permette que, quand on n’est pas en train de faire le “whack a potato”, ça ne clique plus partout et, surtout, à la limite, que ça relance tout seul une partie de “potato” après 5 minutes passées ? je n’ai aucune connaissance en codage ;; j’ai déjà passé 2h sur ce “petit” sujet.