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()
That was what I was thinking.
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
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.
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.
wait can I ask what heroes you guys used?
I used Sir Tharin Thunderfist with 3868 health