Hi guys, I am messing up where my paladins are supposed to heal lowestFriend, if their health is below 200, however I don’t know how to use the return from the previous function in another, please help. My code is below.
# Your goal is to protect Reynaldo
# Find the paladin with the lowest health.
def lowestHealthPaladin():
lowestHealth = 99999
lowestFriend = None
friends = hero.findFriends()
for friend in friends:
#if friend.type != "paladin":
# continue
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend
return lowestFriend
def commandPaladin(paladin):
nearestEnemy = paladin.findNearest(paladin.findEnemies())
lowestFriend = lowestHealthPaladin()
if paladin.pos.x < 70:
hero.command(paladin, "move", {"x":paladin.pos.x + 2})
if lowestFriend:
if paladin.canCast("heal") and lowestFriend.health < 200:
hero.command(paladin, "cast", "heal", lowestFriend)
if paladin.health < 200:
hero.command(paladin, "shield")
elif nearestEnemy:
hero.command(paladin, "attack", nearestEnemy)
pass
# Heal the paladin with the lowest health using lowestHealthPaladin()
# You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
# Paladins can also shield: command(paladin, "shield")
# And don't forget, they can attack, too!
def commandPeasant(peasant):
nearestItem = peasant.findNearest(peasant.findItems())
if nearestItem:
hero.command(peasant, "move", nearestItem.pos)
pass
def commandGriffin(griffin):
enemy = griffin.findNearest(griffin.findEnemies())
if enemy:
hero.command(griffin, "attack", enemy)
pass
def summonGriffin():
if hero.gold >= hero.costOf("griffin-rider"):
hero.summon("griffin-rider")
else:
pass
def summonPeasant():
if hero.gold >= hero.costOf("peasant"):
hero.summon("peasant")
else:
pass
def commandFriends():
# Command your friends.
friends = hero.findFriends()
for friend in friends:
if friend.type == "peasant":
commandPeasant(friend)
pass
elif friend.type == "griffin-rider":
commandGriffin(friend)
pass
elif friend.type == "paladin":
commandPaladin(friend)
#summonPeasant()
while True:
commandFriends()
summonGriffin()
# Summon griffin riders!