Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pixel color and action
#1
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

  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)      
Reply


Messages In This Thread
Pixel color and action - by Sartre - Apr-12-2023, 06:25 PM
RE: Pixel color and action - by deanhystad - Apr-12-2023, 10:52 PM
RE: Pixel color and action - by Sartre - Apr-12-2023, 11:29 PM
RE: Pixel color and action - by deanhystad - Apr-13-2023, 02:11 AM
RE: Pixel color and action - by Sartre - Apr-13-2023, 03:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Voxel to pixel graphics voicemail 3 1,650 Nov-19-2023, 09:45 AM
Last Post: paul18fr
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 3,286 Oct-25-2023, 09:09 AM
Last Post: codelab
  Dynamic pixel display jerryf 2 1,426 Mar-17-2023, 07:26 PM
Last Post: jerryf
Question Running an action only between certain times alexbca 9 3,291 Mar-15-2023, 04:21 PM
Last Post: deanhystad
  Checkbox itens with a button to run action Woogmoog 3 1,725 Dec-19-2022, 11:54 AM
Last Post: Woogmoog
Question Running an action only if time condition is met alexbca 5 2,321 Oct-27-2022, 02:15 PM
Last Post: alexbca
  Plotting Pixel Intensity Doev 0 2,332 Oct-21-2020, 10:56 PM
Last Post: Doev
  What is the best way to search for a pixel in a screenshot? TheZadok42 1 3,551 May-15-2020, 12:37 PM
Last Post: scidam
  Fast get pixel and oparate. storzo 7 8,818 Aug-26-2019, 07:36 PM
Last Post: Larz60+
  Have an amount of time to perform and action CookieGamez2018 1 3,552 Dec-21-2018, 07:12 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020