Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Grim Determination Paladins not healing

Help me! My hero.command(paladin, "cast", "heal", lhealth) line is not working properly somehow and I do not know how to fix it.
here is my code:

# 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!
    if paladin.canCast('heal'):
        lhealth = lowestHealthPaladin()
        if lhealth and lhealth.health < 525 and paladin.type == "paladin":
            hero.command(paladin, "cast", "heal", lhealth)  
    if paladin.health < 200:
        hero.command(paladin, "shield")
    else:
        enemy = paladin.findNearestEnemy()
        if enemy:
            hero.command(paladin, "attack", enemy)
    pass

def commandPeasant(peasant):
    coin = peasant.findNearestItem()
    if (peasant.id == 'Hector' and coin.pos.y >= 38) or (peasant.id == 'Rose' and coin.pos.y <= 38):
        hero.command(peasant, "move", coin.pos)

def commandGriffin(griffin):
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.command(griffin, "attack", enemy)

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!
    while hero.gold >= hero.costOf('griffin-rider'):
        hero.summon('griffin-rider')

Hi @Moonkak3 welcome to the CodeCombat discourse.
You’re right that the casting heal isn’t working.
I think it’s something to do with this:

if paladin.health < 200:
    hero.command(paladin, "shield")

I would get rid of that anyway, I don’t see the point of making them shield. It just makes them die slower without doing anything to stop it.
I would also make the paladins defend their own position. It sounds a bit odd, but it keeps them from running away and they attack nicely in a little formation.
(hero.command(paladin, "defend", paladin))
A problem you will encounter at this point is the healing section. To fix it definde lhealth outside the if statement and check all the conditions on the first if statement.
Once I did that I won with the bonus, and none of my paladins or my griffin-riders died.
I hope this helps,
Danny

tysm! i will try this right now