Apr-12-2023, 06:25 PM
I am very new to Python and decided to build a game bot as a means of learning. Please bear with me..
GOAL:
Part of my program evaluates a specific pixel, checks for the R value for that pixel, moves the mouse cursor to that x,y location and performs a left click until that pixel no longer equals that R value.
In an effort to learn, I am trying to make this as polished as I can and get it to be as flawless in timing and function as possible.
PROBLEM:
While I have working code that performs the exact same function noted above in other areas of the program, in this specific area, it will not function.
When an enemy is killed, it can drop a loot container but this is not consistent. The code I wrote invokes the key press that would open that loot container if it existed and if the container doesn't exist, then nothing happens and the program repeats when the enemy spawns again and is killed.
If a loot container does exist, then the code will open it and a new, top layer window will appear. There is a button on this new window that allows you to take the items but it has two functions depending on what is in the loot container.
1. The container only has low value items in it
2. The container has both low and high value items in it
If 1 is true, then only one press of the button is required to take all of the items and the window closes
If 2 is true, then the first press of the button takes the low value items, and a second press is required to take the high value items.
The loot container button is pressed with a left click. However, left click is also used for attacking, so if scenario 1 is true, then an unnecessary attack occurs where I hard coded two left click functions in the event that scenario 2 was true. I rewrote the code to check for pixel RBG value because the button is highly distinguishable from the world environment.
I can get the container window to open but I cannot get the mouse to move to the button pixel coordinates based on the pixel [0] value.
QUESTIONS:
1. Can you code to look for more than one RGB value of a pixel?
(My thoughts here are that with more information, it maybe easier to find)
If so, can you provide an example of what that might look like compared to my code below?
2. Is this use of pixels and the use of their respective RGB values to perform and action, typically not the best way to do this?
If true, what is the better way?
CODE SECTION:
I know there are far better way to write this code but this is what I know as of today
Everything works perfectly up until the 4th IF statement
GOAL:
Part of my program evaluates a specific pixel, checks for the R value for that pixel, moves the mouse cursor to that x,y location and performs a left click until that pixel no longer equals that R value.
In an effort to learn, I am trying to make this as polished as I can and get it to be as flawless in timing and function as possible.
PROBLEM:
While I have working code that performs the exact same function noted above in other areas of the program, in this specific area, it will not function.
When an enemy is killed, it can drop a loot container but this is not consistent. The code I wrote invokes the key press that would open that loot container if it existed and if the container doesn't exist, then nothing happens and the program repeats when the enemy spawns again and is killed.
If a loot container does exist, then the code will open it and a new, top layer window will appear. There is a button on this new window that allows you to take the items but it has two functions depending on what is in the loot container.
1. The container only has low value items in it
2. The container has both low and high value items in it
If 1 is true, then only one press of the button is required to take all of the items and the window closes
If 2 is true, then the first press of the button takes the low value items, and a second press is required to take the high value items.
The loot container button is pressed with a left click. However, left click is also used for attacking, so if scenario 1 is true, then an unnecessary attack occurs where I hard coded two left click functions in the event that scenario 2 was true. I rewrote the code to check for pixel RBG value because the button is highly distinguishable from the world environment.
I can get the container window to open but I cannot get the mouse to move to the button pixel coordinates based on the pixel [0] value.
QUESTIONS:
1. Can you code to look for more than one RGB value of a pixel?
(My thoughts here are that with more information, it maybe easier to find)
If so, can you provide an example of what that might look like compared to my code below?
2. Is this use of pixels and the use of their respective RGB values to perform and action, typically not the best way to do this?
If true, what is the better way?
CODE SECTION:
I know there are far better way to write this code but this is what I know as of today
Everything works perfectly up until the 4th IF statement
def click(x,y): win32api.SetCursorPos((x,y)) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0) time.sleep(0.1) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0) time.sleep(0.9) #ATTACK SKILLS AND CONTAINER LOOTING if pyautogui.pixel (1096,127) [0] == 16: click(1096,127) if pyautogui.pixel(1096,127) [0] != 16: time.sleep(0.25) pyautogui.keyDown('shift') #opens loot container time.sleep (0.1) pyautogui.keyUp('shift') time.sleep(0.25) if pyautogui.pixel (1021,724) [0] == 36: #identifies the pixel located on the loot button time.sleep(0.1) click(1021,724) #performs click for small value items and continues clicking for high value items if pyautogui.pixel (1021,724) [0] != 36: time.sleep(28)