This works. The only error is the fact that i had to add command() again but its fine it all works
def command():
friends = hero.findFriends()
for friend in friends:
if friend.type == 'soldier':
badGuy = friend.findNearestEnemy()
if badGuy:
hero.command(friend, "attack", badGuy)
def summon():
item = hero.findNearestItem()
if hero.gold > 20:
hero.summon("soldier")
elif item:
hero.move(item.pos)
while True:
command()
summon()
enemy = hero.findNearestEnemy()
if enemy:
command()
hero.attack(enemy)
if hero.canCast("chain-lightning", hero.findNearestEnemy()):
hero.cast("chain-lightning", enemy)
if hero.isReady("consecrate") == True:
hero.consecrate()