[SOLVED] Kithgard Apprentice Level Help

Hi guys. I am stuck on Kithgard Apprentice and I am quite stuck with how to get hero and command my paladin to attack without getting bounced back by the skeletons and that horrendous warlock. Here is my code and help would be very much appreciated:

# Your goal is to survive.
# Also have fun. Maybe win in the leaderboards!
# Good thing you never stumbled into this room the first time you were here, amirite?
def attackEnemies():
    enemy = hero.findNearest(hero.findEnemies())
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        if hero.isReady("throw"):
            hero.throw(enemy)
        else:
            hero.attack(enemy)

def summonTroops():
    if hero.gold >= hero.costOf("paladin"):
        hero.summon("paladin")

def commandTroops():
    friends = hero.findFriends()
    for friend in range(len(friends)):
        enemy = hero.findNearest(hero.findEnemies())
        if enemy:
            hero.command(friend, "attack", enemy)
        if friend.canCast("heal") and hero.health <= 1000:
            hero.command(paladin, "cast", "heal", hero)

I am using Gordon by the way

2 Likes

Please, can you post link to the level?

3 Likes
1 Like

Another thing, I keep on getting this error that really should not be there seeing as it has worked in previous levels:

1 Like

Try using friend in friends.

2 Likes

This is my new code:

# Your goal is to survive.
# Also have fun. Maybe win in the leaderboards!
# Good thing you never stumbled into this room the first time you were here, amirite?
def lowestHealthFriend():
    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 summonTroops():
    if hero.gold >= hero.costOf("paladin"):
        hero.summon("paladin")

def commandTroops():
    friends = hero.findFriends()
    for friend in friends:
        if friend.canCast("heal"):
            weakFriend = lowestHealthFriend()
            if weakFriend:
                hero.command(friend, "cast", "heal", weakFriend)
        enemy = friend.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)
        enemy = friend.findNearestEnemy()
        if friend.distanceTo(enemy) > 10:
            hero.command(friend, "shield")

        
def attackEnemies():
    enemy = hero.findNearest(hero.findEnemies())
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        if hero.isReady("throw"):
            hero.throw(enemy)
        else:
            hero.attack(enemy)


while True:
    summonTroops()
    commandTroops()
    attackEnemies()

The enemy needs to be in throw range.

1 Like

I’ve done that but my paladin does not heal me but it heals the skeletons (???). Any help @MidnightWolf39, @dedreous, and @AnSeDra ?

1 Like

Can you post your new code?

Andrei

2 Likes

Try:

friends = hero.findFriends()
if friends:
    for friend in friends:
2 Likes
def lowestHealthFriend():
    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 summonTroops():
    if hero.gold >= hero.costOf("paladin"):
        hero.summon("paladin")

def commandTroops():
    friends = hero.findFriends()
    for friend in friends:
        if friend.canCast("heal"):
            weakFriend = lowestHealthFriend()
            if weakFriend:
                hero.command(friend, "cast", "heal", weakFriend)
        enemy = friend.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)
        enemy = friend.findNearestEnemy()
        if friend.distanceTo(enemy) > 10:
            hero.command(friend, "shield")

        
def attackEnemies():
    enemy = hero.findNearest(hero.findEnemies())
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        if hero.isReady("throw") and hero.distanceTo(enemy.pos) < hero.throwRange:
            hero.throw(enemy)
        else:
            hero.attack(enemy)


while True:
    summonTroops()
    commandTroops()
    attackEnemies()

1 Like

What is your equipment?

Andrei

2 Likes

1 Like

Then with what helps you this since you do not play with a ranger?

Andrei

2 Likes

I thought it might buy me a little extra time.

1 Like

Because in this level you need just survive, I think you should go to that door, summon paladin, which can kill it, and go inside the room. Then, get all items, and summon lots of archers. Then shield, and your troops will defend you.

3 Likes

How do you open the door? When I was reading a post from, I think it was either @MunkeyShynes or @Deadpool198, they said they could not open the door, only with Okar stomping near it.

2 Likes

I need to go now. i will reply to any more comments tomorrow. Bye for now.

2 Likes

Your hero can’t, but your friends can.

3 Likes

Alright I will try tomorrow.

2 Likes