Recommended Posts

Welcome to coding with Taco.

Here are the requirements:

Python 3.7
pip install opencv-python
pip install PyAutoGUI

The code editor I use is VS Code or VS Studio , you can use whatever you like.
 

 

The goals:

Open Battle.net

Select WoW (I will not be going over switching from WoW to WoW Classic, but you should be able to understand how to do that from this tutorial)

Hit the play button
Select the Server
And accept the full warning message if present.

 

Might seem tough but it is easier than you would expect.

First, lets go through the process the script will have to go. Take screenshots of every step and save them.
Open battle net, select the game, hit the play button, wait for connection, select the server, accept the warning.

Create your new python file.

Set your imports

We are going to want to import:

import os	
import time
import pyautogui

 

Now as a requirement above, I mention opencv-python. PyAutoGUI will use it on its own without you having to import to script.

So now the easy part. Open Battle.Net. File your file location for Battle.net. You can right click on the icon and open file location.

Mine is here:

C:\Program Files (x86)\Battle.net\Battle.net Launcher.exe

We will use the import os to launch/bring to the front Battle.net

os.startfile('C:\Program Files (x86)\Battle.net\Battle.net Launcher.exe')

 

We can run the script to make sure it opens Battle.Net to see if it works.

Now, we are going to want to wait maybe two seconds to make sure it opens.

Waiting is also called sleeping.
So we will put:

time.sleep(2)

The script will wait 2 seconds.

Now, we are going to want to edit our first photo. We want to get the image from the side bar like this:
image.png.cd7b2cc5d5eb3d73b67261f09ce20c69.png

Save the image as something understandable like WoWButton.png

Now back to the script!

PyAutoGUI is going to be doing all the hard work here.

PyAutoGUI has a function to find an image on the screen called locationOnScreen, simple right?

# Gray Scale to remove colors to make it easier to match
# .9 Confidence just because the background color noise
wowIcon = pyautogui.locateOnScreen('WoWButton.png', grayscale=True, confidence=.9)

wowIcon will equal the position on screen the image is found.

If you print it to the console, you will see top, bottom, left, right with the cords on screen.

We will want to make sure it clicks in the center of the button.
So we got to center it and then get what those mouseX and mouseY cords will be:

# Center the mouse
wowIcon = pyautogui.center(wowIcon)
wowIconx, wowIcony = wowIcon

Again, PyAutoGUI is doing all the hard work.

Now, you just got to click on it:

#Click!
pyautogui.click(wowIconx, wowIcony)

 

Now, not everything will just let you click on it without the mouse moving. I'd imagine it is because they want to make it harder for bots.
An easy fix and one that was needed when selecting the server is by moving the mouse. This can be done like this:
 

# Find the server name
serverName = pyautogui.locateOnScreen('serverIcon.png', grayscale=True, confidence=.9)
 
# Center it!
serverName = pyautogui.center(serverName)
 
# and well click it.
serverNamex, serverNamey = serverName
pyautogui.moveTo(serverNamex + 1, serverNamey + 1)
time.sleep(.5)
pyautogui.click(serverNamex, serverNamey)

 

So like before, we created an image of the server name:

image.png.e66f74cab94726f4fef994abbe477e24.png

Then we found it, moved the mouse to the location. I made it move 1 pixel higher on the x and y just so there is some more movement when clicking. The delay isn't really needed but makes it seem more human.

 

Attached is the full script with a batch file. You can use the task scheduler to launch the script at a specific time or just to make it open quicker while you do something else.

 

I hope you learned something!

 

Attached is the script to prevent AFK disconnect. 
Try at your own risk. I am not sure if this will be detected as a bot. 
 

import time
import random
import pyautogui
 
def Forward():
     return pyautogui.press('w')
 
def Back():
     return pyautogui.press('s')
 
def Left():
     return pyautogui.press('a')
 
def Right():
      return pyautogui.press('d')
 
switcher = {
          0: Forward,
          1: Back,
          2: Left,
          3: Right
     }
 
def direction(argument😞
     # Get the function from switcher dictionary
     func = switcher.get(argument, "nothing")
     # Execute the function
     return func()
 
while True:
     time.sleep(random.randint(1,10))
     pyautogui.press('space')
     time.sleep(random.randint(1,10))
     direction(random.randint(0,3))

 

 

Updated.zip

Press Space.py

Share this post


Link to post
Share on other sites
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

Recent Topics

Popular Topics

About us

Warpigs is a semi-hardcore multi game community, for both MMOs and other genres. Our core, which has largely remained the same, started back in 2014. Warpigs first got started in Wildstar and has since branched out to several other game including, Black Desert Online, Overwatch, Heroes of the Storm as some of our most active games. We also have a strong internal following for both Dauntless and Ashes of Creation.
 

Warpigs function as a tight knit family-esque guild, which is not to say that our conversations are G-rated. Quite the opposite, but when you're one of us, we've got your back. Words fly pretty freely, and I'm always of the opinion that if you play an MMO, or any game with a social player base, you need thick skin and know not to take things personally. With that being said, we are a well organised and have a fairly mature membership, and as such we offer a very stable guild that we hope will be here for many more years to come.
 

Warpigs are dedicated to a friendly, team focused, fun-loving gaming environment where every member is important and not just a number on a roster. We seek to foster long term friendships among members and enhance the online gaming experience by virtue of those friendships.