Skip to content

Instantly share code, notes, and snippets.

@nayminlwin
Last active July 20, 2022 03:56
Show Gist options
  • Save nayminlwin/39734e7ffe604909f5c2bf20d5586379 to your computer and use it in GitHub Desktop.
Save nayminlwin/39734e7ffe604909f5c2bf20d5586379 to your computer and use it in GitHub Desktop.
Final Fantasy X auto-lightning dodger modified for wayland desktop. Only tested on wayland desktop but should work on all platform.
# Modified from : https://gist.github.com/fritz-c/f341a1b588564c0a73ffddd684151acf
# to use pyscreenshot and pyninput to make it work on linux wayland desktop
# Install python dependencies - Pillow pynput pyscreenshot
# Dependency for wayland desktop - grim (screen grab tool)
import time
import pyscreenshot as screen
from PIL import Image, ImageStat
from pynput.keyboard import Controller
COLOR_MINIMUM_THRESHOLD = 150
KEYPRESS_DURATION_SEC = 0.1
kb = Controller()
def check_if_whited_out():
# Adjust screen grab backend and screen location here
# Can remove backend parameter to use the default.
# Adjust the bbox params to correctly point to game screen. Use test_screen_grab.py to see if the location is correct.
# Screen grab fps speed depends on backend used. Most should be fast enough to detect lightning on game screen.
img = screen.grab(backend="grim",bbox=(1400,100,1500,200))
extrema = ImageStat.Stat(img).extrema
return all(e[0] > COLOR_MINIMUM_THRESHOLD for e in extrema)
def lightning_dodger():
dodge_count = 0
last_is_whited_out = False
while True:
is_whited_out = check_if_whited_out()
if is_whited_out and not last_is_whited_out:
# Using keyboard 'c' key for dodge button. Change here if you're using other key.
kb.press('c')
time.sleep(KEYPRESS_DURATION_SEC)
kb.release('c')
dodge_count += 1
print(f"{dodge_count}x you're welcome")
last_is_whited_out = is_whited_out
lightning_dodger()
# Run this to see if the screen grab is correctly pointing to game screen
# Run - python ./test_screen_grab.py
# then check the generated 'screen.png' image
import pyscreenshot as ImageGrab
from PIL import Image, ImageStat
im = ImageGrab.grab(backend="grim",bbox=(1400,100,1500,200))
# print(ImageStat.Stat(im).extrema)
im.save('screen.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment