Making an auto training bot for Pokemon Black with python!!!
Hwlo There!!! So Today I plan on making an auto trainer bot for my pokemon black nuzlocke!!
I and my brother are together doing a nuzlocke
So if you don't know what a nuzlocke is... Its like a challenge in pokemon games where there are some rules.. Some of the most common rules are:
1) You can catch only the first pokemon you find on a route (like 1, or even an area...)
2) If your pokemon faints, it dies... What I mean here is that whenever one of your pokemon faints, you cannot use it any further and it goes in the box.
3) If you lose a battle, the run has ended.. Here I mean that if in a battle all your pokemon lose and you lose, then the run has ended even tho you have pokemon in the box. So Like in a hard battle all your pokemon lose, the run has ended and you have to start all over again.
4) Nicknaming all pokemon you catch is necessary.
So here training pokemon is very necessary... Like an underleveled mon can lead to the death of it and your whole run too!!
So here I was training my mons before the striaton gym so that my underleveled mons come to their level... and this was too hard as the wild mons are too low leveled and it would take me like an hour to get them up 2 levels... So I planned on writing a bot for it pog!!
I would not automate the whole process altogether as its too complex!! I would first automate the finding a random mon process i.e. running randomly in the wild.. So lets get started!!
So I opened a py file in vscode and imported the random and the pyautogui library. After that I created an array of the following value:
keysss=['up','down','left','right']
These are taken for pyautogui values that we will randomize(in our desmume settings we have the arrow keys for movement)
Then a for loop for pressing the keys in a loop for some times.
Here we use the random library to choose a random choice from the array when the loop is running. Then we use pyautogui.press(random.choice(keysss).
But its too fast... So we can now import the time library... Then in the for loop add time.sleep(0.5) before the pyautogui.press.
But wait... How do I make it toggle-able?
So now another library to import lol!!!!
import keyboard
The keyboard library helps us to listen to keyboard inputs like the pyautogui library simulates it!!
We have to also put the for loop in a function and then add a keyboard hotkey.
keyboard.add_hotkey('`',lambda:loop())
#I like to use ` you can use anything else too
So the total code is:
import random
import keyboard
import pyautogui
import time
keysss=['up','down','left','right']
def loop():
for x in range(10):
time.sleep(0.5)
pyautogui.press(random.choice(keysss))
keyboard.add_hotkey('`',lambda:loop())
But in Black we also run cuz its too slow!! I need to add that too!!
Total code:
import random
import keyboard
import pyautogui
import time
keysss=['up','down','left','right']
def loop():
for x in range(10):
pyautogui.keyDown('x')
time.sleep(0.5)
pyautogui.press(random.choice(keysss))
pyautogui.keyUp('x')
keyboard.add_hotkey('`',lambda:loop())
So That code doesn't work lol!!
Ah so did some changes and the code that works is :
import random
import keyboard
import pyautogui
keysss=['up','down','left','right']
def loop():
for x in range(3):
sus=random.choice(keysss)
pyautogui.keyDown('x')
pyautogui.keyDown(sus)
pyautogui.keyUp(sus)
pyautogui.keyUp('x')
keyboard.add_hotkey('f10',lambda:loop())
input()
So yes thats a little helpful truly!!
So I tweaked a few stuff:
import random
import keyboard
import pyautogui
import time
keysss=['up','down','left','right']
def loop():
for x in range(3):
sus=random.choice(keysss)
pyautogui.keyDown('x')
pyautogui.keyDown(sus)
pyautogui.keyUp(sus)
pyautogui.keyUp('x')
keyboard.add_hotkey('/',lambda:loop())
input()
So That's it for today!!!
Bye!!!! Catch 'em all!!