22import pydirectinput
33import time
44import random
5+ import mss
6+ import numpy as np
7+ from PIL import Image
8+ import gc
59
610def main ():
711 """
812 Main function for the program
913 """
10-
1114 # Finds all Windows with the title "New World"
1215 newWorldWindows = pyautogui .getWindowsWithTitle ("New World" )
1316
@@ -31,7 +34,7 @@ def main():
3134 time .sleep (.1 )
3235
3336 # Auto Run Key
34- autowalkKey = '= '
37+ autowalkKey = '0 '
3538
3639 # Seconds to move foward
3740 fowardMoveTotal = 20
@@ -43,51 +46,83 @@ def main():
4346 flip = 1
4447
4548 # Turn 90 degrees, value will be different for you, im on a 4k monitor
46- flipMouseMove = 2000
49+ flipMouseMove = 3500
50+
51+ # If the bot has stopped moving
52+ stopped = False
4753
4854 # Making tuple with data from the window for later use
4955 region = (newWorldWindow .left , newWorldWindow .top , newWorldWindow .width , newWorldWindow .height )
56+ mssRegion = {"mon" : 1 , "top" : newWorldWindow .top , "left" : newWorldWindow .left + round (newWorldWindow .width / 3 ), "width" : round (newWorldWindow .width / 3 )* 2 , "height" : newWorldWindow .height }
57+
58+ # Prep screenshots, walk forward and log time
59+ sct = mss .mss ()
60+ pyautogui .press (autowalkKey )
61+ startTime = time .time ()
5062
5163 # Main bot loop, runs forever use CTRL+C to turn it off
5264 while True :
65+ # Get Screenshot and reset unstuck tracker
66+ sctImg = Image .fromarray (np .array (sct .grab (mssRegion )))
67+ stuckTracker = 0
68+
5369 # Find that image on screen, in that region, with a confidence of 65%
54- if pyautogui .locateOnScreen ("imgs/e0.png" , grayscale = True , confidence = .65 , region = region ) is not None :
70+ if pyautogui .locate ("imgs/e0.png" , sctImg , grayscale = True , confidence = .8 ) is not None :
71+ # If not stopped, stop
72+ if not stopped :
73+ pyautogui .press (autowalkKey )
74+
75+ stopped = True
5576 pyautogui .press ('e' )
56- time .sleep (1 )
57- continue
77+ print ("Pressing e" )
78+ time .sleep (1.2 )
79+
80+ # Get a new Screenshot
81+ sctImg = Image .fromarray (np .array (sct .grab (mssRegion )))
82+
83+ # Check if the 'q' image is on screen
84+ while pyautogui .locate ("imgs/1.png" , sctImg , grayscale = True , confidence = .8 ) is None :
85+ time .sleep (.5 )
86+ sctImg = Image .fromarray (np .array (sct .grab (mssRegion )))
87+ print ("Waiting..." )
88+ gc .collect ()
5889
59- # Do I got to explain?
60- pyautogui .press (autowalkKey )
90+ # If stuckTracker gets to 15, move the mouse
91+ if stuckTracker == 15 :
92+ pydirectinput .move (5 , 0 , relative = True )
93+ stuckTracker = 0
6194
62- # Randomly move foward 0 - 1.5 seconds
63- temp = 1.5 * random .random ()
64- currentFoward += temp
65- time .sleep (temp )
95+ stuckTracker += 1
6696
67- # Brah, you know
68- pyautogui .press (autowalkKey )
97+ print ("Done waiting" )
98+ continue
99+
100+ # If bot is stopped, make the bot move again
101+ if stopped :
102+ pyautogui .press (autowalkKey )
103+ stopped = False
104+ startTime = time .time ()
105+
106+ # Calculated how much the bot has moved forward
107+ currentFoward += (time .time () - startTime )
108+ startTime = time .time ()
69109
70110 # Flippy flip if you hitty hit the max move time (fowardMoveTotal)
71111 if currentFoward >= fowardMoveTotal :
72112 # Reset the move foward
73113 currentFoward = 0
74114
75- # Move the mouse 90 degrees
76- pydirectinput .move (flipMouseMove * flip , 1 , relative = True )
77-
78- # Move Foward 1.5 secs
79- pyautogui .press (autowalkKey )
80- time .sleep (1.5 )
81- pyautogui .press (autowalkKey )
82-
83- # Move the mouse 90 degrees
84- pydirectinput .move (flipMouseMove * flip , 1 , relative = True )
115+ for i in range (0 , flipMouseMove , round (flipMouseMove / 5 )):
116+ # Moving the mouse a 5th of the total move amount
117+ pydirectinput .move (round (flipMouseMove / 5 ) * flip , 0 , relative = True )
118+ # Wait for .3 seconds
119+ time .sleep (.3 )
85120
86121 # Flippy flippy the value. Evil math.
87122 flip *= - 1
88123
89- # Sleeping for the animation
90- time . sleep ( .1 )
124+ # Garbage man
125+ gc . collect ( )
91126
92127
93128# Runs the main function
0 commit comments