mameau redbubble image
Get Shirty!Keep us online, Buy some kit.

Clash of Clans Script – Automated Farming with ADB, RaspberryPi, Linux & Python

UPDATE: the TH11 update will kick you off after a set period known as a “Personal Break Timer”, so this no longer works as it did in older versions, feel free to update the code below. Code was just a proof-of-concept anyway.

The below was published 06/04/2015

I posted a video of a Clash of Clans script for “always online” using ADB & Python a while back on Youtube, never did get around to posting the script itself. About time I did i’d say.

This Clash of Clans script will randomly generate a touch event (providing you have a recent enough version of Android, 4.1+ IIRC) within the bounds of your devices screen, you may configure touch regions within the script. You will need ADB configured and working correctly which is covered elsewhere around the net and will not be covered here. In the video we ran this on a Raspberry Pi as it was more economical than leaving the PC on 24/7. Still the script can be run anywhere you can get python going.

The Script

#!/usr/bin/python
#
# Clash of Clans farmer

import time
import subprocess
import random
import sys

# General Settings
title = "Clash of Clans"

# Edit depending on you screensize
min_x = 230
max_x = 1030
min_y = 200
max_y = 600

# Interval settings
ilow = 5
ihigh = 29

# ADB settings
adbcmd = 'adb'
adbshell = '%s shell' % adbcmd
adb_it = '%s input tap' % adbshell


def cmd(command, stdout=False):
  ''' execute the commands through Popen
  return the output of popen'''
  command = "%s" % (command)
  proc=subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
  if stdout:
    return proc.stdout.read()
  else:
    return proc.communicate()[0]
  return

def wstdout(msg):
    sys.stdout.write(msg)
    sys.stdout.flush()

def setup_tap(x, y):
    interval = random.randint(ilow,ihigh)
    cmd("%s %s %s" % (adb_it, x, y))
    msg_interval(interval)
    return

def msg_interval(interval):
  while interval > 0:
    wstdout("Next update in %d seconds     \r" % interval)
    time.sleep(1)
    interval -= 1
  wstdout("Updating now!                 \r")
  return

def main():
  print "%s, farmer started" % title
  while True:
    setup_tap(random.randint(min_x,max_x),random.randint(min_y,max_y))
  return

if __name__ == '__main__':
  main()

 

 

Show Buttons
Hide Buttons