I am trying to find the Arrow tower with the lowest health but im unsure of how to implement it
coin = hero.findItems()
Up = 83, 77
Mid = 83, 51
Down = 84, 22
friend = hero.findNearestFriend()
soldierIndex = 0
friends = hero.findFriends()
def lowestHealthATfriend():
lowestHealth = 99999
lowestFriend = None
friends = hero.findFriends()
if friends.type == "arrow-tower":
ATfriend = hero.findNearestFriend()
for ATfriend in friends:
if friend.type == 'ATfriend':
continue
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = ATfriend
while True:
Up = 83, 77
Mid = 83, 51
Down = 84, 22
items = hero.findItems()
bestItem = None
bestValue = 0
itemsIndex = 0
# Loop over the items array.
# Find the item with the highest valueOverDistance()
if friends.type == "arrow-tower":
ATfriend = hero.findNearestFriend()
while itemsIndex < len(items):
item = items[itemsIndex]
if item.value / hero.distanceTo(item) > bestValue:
bestItem = item
bestValue = item.value / hero.distanceTo(item)
itemsIndex += 1
if bestItem:
if hero.isReady("jump"):
hero.jumpTo(bestItem)
hero.moveXY(bestItem.pos.x, bestItem.pos.y)
if hero.gold >= 20 :
x = ATfriend.pos.x + 6
y = ATfriend.pos.y
hero.moveXY(x, y)
im new to coding so if i miss something obvious would you please be patient with me