# If the peasant is damaged, the flowers will shrink!
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
# Define the function: commandSoldiers
def commandSoldiers():
friends = hero.findByType("soldier")
for friend in friends:
enemy = hero.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
peasant = hero.findByType("peasant")[0]
while True:
summonSoldiers()
# commandSoldiers()
# pickUpNearestCoin()
commandSoldiers()
pickUpNearestCoin()
@Ry4n_17, without re-reading the entire thread again, I believe someone said you need to keep your soldiers close to Hector. I found this not necessary. In my ‘def commandSoldiers()’, I simply have them attack if there is an enemy.
In your ‘def pickUpNearestCoin()’, I would simplify the move command with simply ‘hero.move(item.pos)’. I used a different method to find the nearest, but I think yours should work fine. If not, I’ll try to explain mine.
So now i have this, i make my soldiers atack and i changed my move, stil dosent work
# If the peasant is damaged, the flowers will shrink!
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
# Define the function: commandSoldiers
def commandSoldiers():
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
soldiers = hero.findByType("soldier")
for soldier in soldiers:
if friend.type == "soldier":
hero.command(soldier, "attack", enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
item = hero.findNearestItem()
if item:
hero.move(item.pos)
peasant = hero.findByType("peasant")[0]
while True:
summonSoldiers()
# commandSoldiers()
commandSoldiers()
# pickUpNearestCoin()
pickUpNearestCoin()