So I have slowly gotten this down and I can’t figure this out at all. I’ve gotten down so that I seem to be able to attack most of the guys and not have much problem, but then my guy keeps running off towards sand yaks and I’ve tried a dozen different ways to exclude sand yaks and several of them caused problem. Please help.
def findWeakestEnemy(): enemies = hero.findEnemies() weakest = None leastHealth = 99999 enemyIndex = 0 # Loop through enemies: while enemyIndex < len(enemies): enemy = enemies[enemyIndex] # If an enemy's health is less than leastHealth: if enemy.health < leastHealth: # Make it the weakest weakest = enemy # and set leastHealth to its health. leastHealth = enemy.health enemyIndex += 1 return weakest while True: # Find the weakest enemy with the function: enemy = hero.findEnemies() weakest = findWeakestEnemy() distance = hero.distanceTo(weakest) if enemy.type != "sand-yak": if hero.canCast("chain-lightning", weakest): hero.cast("chain-lightning", weakest) if hero.isReady("stomp") and distance > 10: hero.stomp(weakest) if hero.isReady("bash") and distance > 10: hero.bash(weakest) elif weakest: hero.attack(weakest) pass
fixed code and indents. Helps if you use the right button.