[SOLVED] Restless Dead Level Help

That is what @Deadpool198 said to do.

Not quite. Have a look at what he suggested again.

I solved that but my hero does not attack the yeti. Why is this?

The Yeti has a health of 180…

Ooooooooooooooooohhhhhhhh. I get it now.

Nope. He still won’t attack the yeti

And the yeti’s health is 300.

So it is. Can you post your code again?

def collect():
    coins = hero.findItems()
    coin = hero.findNearest(coins)
    if coin:
        hero.move(coin.pos)

def summon():
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")

def command():
    soldiers = hero.findFriends()
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        enemts = hero.findEnemies()
        enemt = hero.findNearest(enemts)
        if enemt:
            hero.command(soldier, "attack", enemt)
        else:
            hero.command(soldier, "move", {"x": 31, "y": 40})
        

        
while True:
    summon()
    flag = hero.findFlag()
    if flag:
        distance = hero.distanceTo(flag)
        while distance > 3:
            hero.pickUpFlag(flag)
            distance = hero.distanceTo(flag)
            enemies = hero.findEnemies()
            enemy = hero.findNearest(enemies)
            if enemy and enemy.health <= 300:
                command()
                if hero.isReady("bash"):
                    hero.bash(enemy)
                else:
                    hero.attack(enemy)
            collect()

He won’t do anything else after he kills the yeti.

I’m not an expert but maybe put an else or an elif after the entirety of the

if enemy and enemy.health <= 300:
    command()
    if hero.isReady("bash"):
        hero.bash(enemy)
    else:
        hero.attack(enemy)

and then add collect()

1 Like

That was what I was thinking.

1 Like

Then try it I guess. It can’t hurt to try.

(edit: in looking over my code, I saw that I created an attack function that would attack any enemy that had health greater than 0. maybe adding one here would help?)

It did work but my soldiers won’t attack the skeletons

Post your current code so we can see it.

def collect():
    coins = hero.findItems()
    coin = hero.findNearest(coins)
    if coin:
        hero.move(coin.pos)

def summon():
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")

def command():
    soldiers = hero.findFriends()
    for i in range(len(soldiers)):
        soldier = soldiers[i]
        enemt = hero.findNearestEnemy()
        if enemt:
            hero.command(soldier, "attack", enemt)
        else:
            hero.command(soldier, "move", {"x": 31, "y": 40})
        

def attack():
    enemrs = hero.findEnemies()
    enemr = hero.findNearest(enemrs)
    if enemr and enemr.health > 0:
        if hero.isReady("bash"):
            hero.bash(enemy)
        else:
            hero.attack(enemy)

while True:
    summon()
    flag = hero.findFlag()
    if flag:
        distance = hero.distanceTo(flag)
        while distance > 3:
            hero.pickUpFlag(flag)
            distance = hero.distanceTo(flag)
            enemies = hero.findEnemies()
            enemy = hero.findNearest(enemies)
            if enemy:
                attack()
    coins = hero.findItems()
    coin = hero.findNearest(coins)
    if coin:
        collect()
        command()

Well, first this:

def attack():
    enemrs = hero.findEnemies()
    enemr = hero.findNearest(enemrs)
    if enemr and enemr.health > 0:
        if hero.isReady("bash"):
            hero.bash(enemy)
        else:
            hero.attack(enemy)

your hero has the variable enemrs, so the variable enemy is undefined.

(maybe in your line for command do for soldier in soldiers:)

Second, if I’m not mistaken, the only error is now in how you go about in achieving this.

I didn’t start off the bat with a while loop. Instead, my strategy was to kill the yeti and summon soldiers before I added the while loop for the enemies. Maybe something like this will help?

@dedreous, @AnSeDra, @Deadpool198 can help you better than I can

-@Anna

2 Likes

To start with, no promises I can help you to completion…I try to avoid using flags, unless they are required to pass the level, so not very fluent with them.

The first thing I see is in:

def collect():
    coins = hero.findItems()
    coin = hero.findNearest(coins)
    if coin:
        hero.move(coin.pos)

This method does not seem to pick up all of the coins…it runs only once. Instead, I used an ‘while coin’ loop, which goes something like this:

def collect():
    define nearest coin
    while that coin exists:
        move to coin
        define nearest coin # this 'primes' the loop with a new focus. 
        # This way, all coins will be picked up, then the function will exit

Next, I summoned pallys so I could take advantage of their heal ability. If you have BS4, I would recommend these instead of soldiers.

Take a look and see if these help a bit…they will not (I’m pretty sure) result in completing the level, but they are a step in that direction. Once you have tested, if you choose to, I’ll advise on the other code blocks.

3 Likes

I don’t understand this part and I changed the collect() function to this:

def collect():
    coins = hero.findItems()
    for i in range(len(coins)):
        coin = coins[i]
        if coin:
            hero.move(coin.pos)

It still works.

1 Like

wait can I ask what heroes you guys used?

2 Likes

I used Sir Tharin Thunderfist with 3868 health

2 Likes