[SOLVED]Grim determination (python)


#1

Help

# 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):
    # 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!
    paladin = hero.findNeares(hero.findByType("paladin"))
if paladin.canCast("heal", hero):
    hero.command(paladin, "cast", "heal", hero)
    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)

while True:
    commandFriends()
    # Summon griffin riders!
hero.summon("griffin-rider")


#2

It says paladin not defined.


#3

There’s an indentation problem, but that might be to do with copying it in, and a typo on the hero.findNearest
But that’s all I can see.


#4

I don’t see an indentation but I got the typo


Which one are you going to choose? [polls]
#5

For starters, you need to follow the directions in the commandPaladin(paladin) function. You haven’t done any of that:

    # 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!

After that, you need to create the functions called for in the commandFriends() function. Just think about what the peasants should be doing or the griffin-riders should be doing (once you summon them).


#6

@MunkeyShynes this is my new code, it says target not defined :confused:

# 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):
    # 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!
    lowestHealthPaladin()
    paladin.canCast("heal")
    hero.command(paladin, "cast", "heal", target)
    hero.command(paladin, "shield", target)
    hero.command(paladin, "attack", target)
    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)

while True:
    commandFriends()
    # Summon griffin riders!
hero.summon("griffin-rider")


#7

Oh common, you didn’t put any effort into that at all. By now you already know to put an if conditional before casting spells.

if hero.canCast("spell"):
    hero.cast("spell", target)

You know how to do this. On the first one, you have to define target as the lowestHealthPaladin() so the one with the lowest health gets healed first.

`


#8

22%20AM