Error with sharpshooters help

Hi, I don’t understand what I am doing wrong.
This is for war at the cloudrip mountain. My hero keeps pausing in between getting coins, and for some reason, after my sharpshooters are dead, he does nothing, and doesn’t even command. Here is my code.

hero.cast("haste", self)

while hero.gold < 140:
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
if hero.team == "humans":
    hero.moveXY(79, 72)
    hero.summon("energy-tower")
else:
    hero.moveXY(92, 74)
    hero.summon("energy-tower")
if hero.team == 'humans':
    hero.moveXY(37, 68)
else:
    hero.moveXY(123, 73)
    

summon = ['energy-tower', 'sharpshooter', 'griffin-rider', 'sharpshooter', 'paladin', 'dark-shaman']
def summonTroops():
    type = summon[len(hero.built) % len(summon)]
    if hero.gold > hero.costOf(type):
        hero.summon(type)
def commandHero():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
def commandGriffin():
    soldiers = hero.findByType('griffin-rider', hero.findFriends())
    for soldier in soldiers:
        enemies = hero.findEnemies()
        enemy = soldier.findNearest(enemies)
        if enemy:
            hero.command(soldier, "attack", enemy)
def findBestItem(friend, excludedItems):
    items = friend.findItems()
    bestItem = None
    bestItemValue = 0
    for item in items:
        if item not in excludedItems:
            if bestItemValue < item.value / friend.distanceTo(item):
                bestItemValue = item.value / friend.distanceTo(item)
                bestItem = item
    return bestItem
def commandPeasant():
    peasants = hero.findByType("peasant", hero.findFriends())
    claimedItems = []
    for peasant in peasants:
        item = findBestItem(peasant, claimedItems)
        if item:
            claimedItems.append(item)
            hero.command(peasant, 'move', item.pos)
def commandPaladin():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == 'paladin':
            if friend.canCast("heal", hero) and hero.health < 1284:
                target = hero
                hero.command(friend, "cast", "heal", target)
            if friend.health < 500 and friend.canCast("heal", friend):
                target = friend
                hero.command(friend, "cast", "heal", target)
            else:
                enemies = hero.findEnemies()
                enemy = friend.findNearest(enemies)
                if enemy:
                    hero.command(friend, "attack", enemy)
def commandArcher():
    soldiers = hero.findByType('archer', hero.findFriends())
    for soldier in soldiers:
        enemies = hero.findEnemies()
        enemy = soldier.findNearest(enemies)
        if enemy:
            hero.command(soldier, "attack", enemy)
def commandSniper():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == 'sniper':
            targets = hero.findEnemies()
            for target in targets:
                if target.type == 'sniper':
                    hero.command(friend, "attack", target)
                if target.type == 'witch':
                    hero.command(friend, "attack", target)
                if target.type == 'night-witch':
                    hero.command(friend, "attack", target)
                if target.type == 'sharpshooter':
                    hero.command(friend, "attack", target)
def commandTower():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == 'energy-tower':
            enemies = hero.findEnemies()
            for enemy in enemies:
                if enemy.type == 'griffin-rider':
                    hero.command(friend, "attack", enemy)
                else:
                    enemies = hero.findEnemies()
                    enemy = friend.findNearest(enemies)
                    if enemy:
                        hero.command(friend, "attack", enemy)
def commandSharpshooter():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == 'sharpshooter':
            targets = hero.findByType("sharpshooter", hero.findEnemies())
            target = friend.findNearest(targets)
            if target:
                hero.command(friend, "attack", target)
            else:
                targets = hero.findEnemies()
                for target in targets:
                    if target.type == 'peasant':
                        hero.command(friend, "attack", target)
while True:
    summonTroops()
    commandArcher()
    commandGriffin()
    commandPaladin()
    commandPeasant()
    commandHero()
    commandSniper()
    commandTower()
    commandSharpshooter()

Edit: Figured out why.

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.