Continued from here: Kelvintaph Crusader Help.

I’ve been trying to get my troops to kill the ogres in order of threat. For example:

Witch -> Skeleton -> Ogre M.

I can’t seem to kill all of them before they kill me. Here is my code:

loop:
for friend in self.findFriends():
target = friend.findNearestEnemy()
if target:
self.command(friend, "attack", target)
witch = self.findByType("witch")
if witch:
self.command(friend, "attack", "Yzzrith")
elif witch.health == 0:
self.command(friend, "attack", "Oni")

while self.pos.x < 69:
self.move({'x':69, 'y':15})
self.say("Hi!")
while self.pos.x > 37:
self.move({'x':37, 'y':16})
self.say("Bye!")
for i in range(3):
enemy = self.findNearest(self.findByType("catapult"))
if enemy:
self.attack(enemy)

self.say("Hi!")
while self.pos.x > 37:
self.move({'x':37, 'y':16})
while self.pos.x < 78:
self.move({'x':78, 'y':14})

Any help would be very appreciated. Thank you!

Endercore79

1 Like

Some of that’s my old code; it doesn’t work, so I abandoned it.

Define a function that returns the highest threat enemy, something like this:

def chooseTarget():
# Define lists of enemies you are sorting
if len(list) > 0:
return self.findNearest(list)
elif len(otherList) > 0:
# And so on

Also, here’s a tip for you: I don’t know if you have the Emperor’s Gloves yet, but you can cast chain-lightning through walls, if you can see the target. Kill the nearest Ogre M with it.

1 Like

Hi @ChronistGilver,
Thank you so much! I’ll try the code soon. And yes, I do have the Emperor’s Gloves. I never knew that!

Cheers,
Endercore79

1 Like

I need help with kelvintaph crusder
MY code:

loop:
for friend in self.findFriends():
target = friend.findNearestEnemy()
if target:
self.command(friend, "attack", target)
witch = self.findByType("witch")
if witch:
self.command(friend, "attack", "Yzzrith")
elif witch.health == 0:
self.command(friend, "attack", "Oni")

while self.pos.x < 69:
self.move({'x':69, 'y':15})
self.say("Hi!")
self.say("hi")
while self.pos.x > 37:
self.move({'x':37, 'y':16})
self.say("Bye!")
for i in range(3):
enemy = self.findNearest(self.findByType("catapult"))
if enemy:
self.attack(enemy)

self.say("Hi!")
while self.pos.x > 37:
self.move({'x':37, 'y':16})
while self.pos.x < 78:
self.move({'x':78, 'y':14})
1 Like