Scripting a bot for EOS Knights

in #eos6 years ago

eos-knights1.PNG

EOS Knights is the best blockchain game out there right now. I found it incredibly addictive and quite fun to play. That said there are some requirements to play, so lets go over them right now:

  • Need about 30-40 EOS to play
    • I recommend staking about 30 EOS on CPU (double the official recommendation)
  • EOS account - You can create one by paying about $5 if you don't have a friend create one for you. If you are having problems hit me up and I can help you.
    • Note: this is an official EOS account, not an ERC20 token account or having EOS on an exchange
  • Scatter for Chrome

Now with that said head over to https://game.eosknights.io/ and let's begin. There is plenty of other how-to-play the game out there but basically, you need play to a point you get your knights mostly uncommon-rare items and no longer need the common items which should be level 4+.

For my automation bot, I decided to go with Autoit for simplicity and adaptability. I'd recommend setting this up in a Virtual machine so you can just set it and forget it! This bot is based on the EOS knight being in a chrome maximized window on a resolution of (1600x900). So set your monitor to these dimensions and run the script and let it do the rest.

eos-knights2.PNG

What the bot will do:

  • revive you when you are low on HP
  • sell any common mats you acquire from reviving
  • reset game/refresh browser window with a 5-minute wait if you run out of inventory, cpu maxed, fail bot check, have scatter go boom.

So with that you can see the calls I made for the pixels on the screen and you can modify these for other resolutions if you like. Also, your version of chrome may make a difference V68 and V69(just launched this week) have a different pixel count which may through this bot off. Let me know if you need some help, but include chrome version and resolution you are on. Please note: Autoit emulates actual movement so you can't use the PC while this is running and why I recommend using a VM.

Without further ado here is the code for the au3 script:

#include <AutoItConstants.au3>
Opt("WinTitleMatchMode",2)
Global $notloading = 0
While 1=1
;$health = PixelGetColor( 2181 , 328 ) ;LONG
;$health = PixelGetColor( 2198 , 328 ) ;SHORT
;$randomhealth = Random(2181,2200) ; Rare Farm
$randomhealth = Random(1056,1062) ; Unique Farm
$health = PixelGetColor( $randomhealth , 308 ) ;RANDOM
$menuselect = PixelGetColor(981,442)
If $notloading = 1 Then
    resetgame()
ElseIf $menuselect <> DEC("58CEFF") Then
    MouseClick("left",986,421,1)
ElseIf $health <> DEC("1CFF7D") Then
    revive()
    inventorymenu()
    inventoryselect(1117,423,1119,465)
    inventoryselect(1033,423,1035,465)
    inventoryselect(1200,423,1202,465)
    inventoryselect(1284,423,1286,465)
    inventoryconvert()
EndIf
Sleep(60000)
WEnd

Func resetgame()
    WinActivate("EOS Knights - Google Chrome","")
    WinWaitActive("EOS Knights - Google Chrome","",10)
    Sleep(500)
    Send("{F5}")
    Sleep(300000)
    MouseClick("left",1078,523,1)
    Sleep(7000)
    $notloading = 0
EndFunc

Func inventorymenu()
   MouseClick("left",1158,369,1)
EndFunc

Func inventoryselect($x1,$y1,$x2,$y2)
    $inventory = PixelSearch($x1,$y1,$x2,$y2,0xC9C9C9,15)
    If Not @error Then
        MouseClick("left",$x1,$y1,1)
    EndIf
EndFunc

Func inventoryconvert()
    MouseClick("left",1053,773,1)
    Sleep(500)
    MouseClick("left",1077,556,1)
    Sleep(500)
    cpucheck()
    $scatwnd = WinWait("Scatter","", 10)
    $iState = WinGetState($scatwnd)
    If BitAND($iState, $WIN_STATE_EXISTS) Then
        WinActivate("Scatter","")
        WinWaitActive("Scatter","",10)
        Sleep(500)
        MouseClick("left",1045,688,1)
        Sleep(6000)
        WinActivate("EOS Knights - Google Chrome","")
        WinWaitActive("EOS Knights - Google Chrome","",10)
        MouseClick("left",986,819,1)
    Else
        $notloading = 1
    EndIf
EndFunc

Func revive()
    WinActivate("EOS Knights - Google Chrome","")
    WinWaitActive("EOS Knights - Google Chrome","",10)
    Sleep(500)
    MouseClick("left",1210,465,1)
    Sleep(500)
   $healthcheck = PixelGetColor( 1063 , 525 )
   $cpucheck = PixelGetColor( 1099 , 393 )
   If $healthcheck = DEC("FFFFFF") AND $cpucheck <> DEC("FF0000") Then
        MouseClick("left",1073,573,1)
    EndIf
    cpucheck()
    $scatwnd = WinWait("Scatter","", 10)
    $iState = WinGetState($scatwnd)
    If BitAND($iState, $WIN_STATE_EXISTS) Then
        WinActivate("Scatter","")
        WinWaitActive("Scatter","",10)
        Sleep(500)
        MouseClick("left",1040,688,1)
        Sleep(6000)
        WinActivate("EOS Knights - Google Chrome","")
        WinWaitActive("EOS Knights - Google Chrome","",10)
        MouseClick("left",1115,677,1)
    Else
        $notloading = 1
    EndIf
 EndFunc

Func cpucheck()
   $cpucheck = PixelGetColor( 1099 , 393 )
    If $cpucheck = DEC("FF0000") Then
        Sleep(300000)
        MouseClick("left",1026,669,1)
     EndIf
EndFunc

Enjoy!

Sort:  

Congratulations @christitus! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

Award for the number of comments
Award for the number of comments received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

SteemitBoard - Witness Update
SteemFest³ - SteemitBoard support the Travel Reimbursement Fund.

Support SteemitBoard's project! Vote for its witness and get one more award!

Add the recommended maikurakiluv and receive 1,000 magic water.

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64254.80
ETH 3145.34
USDT 1.00
SBD 3.88