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

Sarven brawl help

here is my code i have rune sword and iron armor leather boots

while True:
    enemy = hero.findNearestEnemy()
    if hero.health < 10:
        hero.say("ouch")
        pass
    else:
        if hero.distanceTo(enemy) < 3:
            if enemy.type == "thrower" or enemy.type == "ogre":
                hero.attack(enemy)
  • also have 2 minute time*

What is your problem?

There are plenty of ways to play this level, that is what makes it fun and challenging. A few things to think about with your code so far.

At this point, you are only attacking two types of enemies and allowing the other types to attack you without any defense or counter attack. Also, the throwers don’t usually get close to you so your combination of distance less than three and thrower type will likely prevent you from attacking the thrower type.

        if hero.distanceTo(enemy) < 3:
            if enemy.type == "thrower" or enemy.type == "ogre":

What hero are you using and what other gear do you have?

I am using Tharin with the Quartz sense stone, mahogany glasses, dynamic flags, crude spike, workers glove, simple wristwatch, progamantion III, leather boots and just purchased emperor’s gloves

Witch means no workers gloves

@ducky i cant attack when i select a yak, and get killed

Maybe you forgot to see if an enemy is there? What do you mean by “selecting” a yak?

I think you’re distance is too small.
3 is the usual attacking distance.
Maybe try something bigger, like 5.
:lion: :lion: :lion:

Do you have a sword equipped or any armor?

You may want to switch from using hero.findNearestEnemy() to hero.findEnemies() to get an array of all the enemies and you can run through them with a ‘for’ loop so you don’t get stuck on one enemy. As you run through the for loop you can check what type of enemy and determine which one you want to attack. Below is a modified version of your original code using the enemies array. Don’t forget the while True: at the beginning.

enemies = hero.findEnemies()
for enemy in enemies:
    if hero.distanceTo(enemy) < 3:
        hero.attack(enemy)
    elif enemy.type == "thrower" or enemy.type == "ogre":
        hero.attack(enemy)

@broosky125 I am using the rune sword and have both the rusted iron helmet and the rusted iron chest-plate

here is my updated code

while True:
    enemies = hero.findEnemies
    enemy = hero.findNearestEnemy()
    for enemy in enemies:
        if hero.distanceTo(enemy) < 5:
            hero.attack(enemy)
        elif enemy.type == "thrower" or enemy.type == "ogre":
            hero.attack(enemy)

it comes up with an error saying TypeError: Need an object

You need to check whether there’s an enemy, not just what it’s type is, or how far away it is. :smile:
:lion: :lion: :lion:

this still comes up with the same error

while True:
    enemies = hero.findEnemies
    enemy = hero.findNearestEnemy()
    if enemy:
        for enemy in enemies:
            if hero.distanceTo(enemy) < 5:
                hero.attack(enemy)
            elif enemy.type == "thrower" or enemy.type == "ogre":
                hero.attack(enemy)

well, the nearest enemy is a yak my code does not do anything else

I tried that but, I did not do anything.

I am going to be gone Monday and Tuesday so I will not be able to fill this out then.

Try if enemy.type!="yak":

You are using the same variable name for two different variables. If you want to use both lines of code, change the name of one of the enemy variables

enemy = hero.findNearestEnemy() 
for enemy in enemies:

and it is not yak, but sand-yak.

enemy.type != "sand-yak"
while True:
    enemies = hero.findEnemies
    boss = hero.findNearestEnemy()
    if boss:
        for boss in enemies:
            if hero.distanceTo(boss) < 5:
                hero.attack(boss)
            elif enemy.type == "thrower" or enemy.type == "ogre":
                hero.attack(boss)

is what i tried because it sounded like what you said but still didn’t work