
Check out the GitHub repository.
Context
In Age of Empires II, it is essential to maintain a steady production of villagers (workers who gather resources to boost your economy and produce other units). Even though there’s a production line at the top of the screen, in the heat of battles one can neglect that aspect and forget to keep producing villagers. In this sense I came up with the idea of creating a python script that, using pyautogui, checks if there are villagers being created in the production queue, and if not, plays a sound alert.
The idea then was for the script to have the villager icon and look for that image in the production queue. The first problem I faced is that the villagers can be male or female. I decided to solve this by modifying the female villager icon inside the game, so that it also uses the image of the male villager.
For it I modified the file at
\AoE2DE\widgetui\icons.jsonand in the Units entry I assigned the same value to the units 015 and 016.
This solved the first problem, but a second one arises: in the production queue there is a progress bar over the icon of the unit being created. This prevented pyautogui from recognizing the icon correctly. This could be solved by decreasing the CONFIDENCE_LEVEL to 0.6.
Then I just set the script to be on a loop and check every 3 seconds.
Requirements
- pyautogui
- playsound==1.2.2
- opencv-python
