That section doesn’t cause an infinite loop for me. It must be another part of your code. Please post all of it. Maybe you haven’t made the other change I suggested.
Thanks. I have been a bit busy but here is the rest of my code:
# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
enemyMissile = hero.findNearest(hero.findEnemyMissiles())
stage = 1
friends = hero.findFriends()
for friend in friends:
hero.command(friend, "move", Vector(0, 38))
def summonPaladin():
if hero.gold >= hero.costOf("paladin"):
hero.summon("paladin")
def lowestHealthPaladin():
lowestHealth = 99999
lowestFriend = None
friends = hero.findFriends()
for friend in friends:
if friend.type != "paladin":
continue
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend
return lowestFriend
def specAttack(target):
if target:
if hero.distanceTo(target) < 100:
while target.health >= 0:
if hero.isReady("slam"):
hero.slam(target)
elif hero.isReady("bash"):
hero.bash(target)
elif enemyMissile and hero.distanceTo(enemyMissile) < 5:
dir = Vector.subtract(enemyMissile.pos,hero.pos)
hero.reflect(dir)
else:
hero.attack(target)
def attack(target):
if target:
specAttack(target)
else:
commandFriends()
def commandPaladin(paladin, stage):
target = paladin.findNearestEnemy()
if target:
if paladin.canCast("heal"):
if hero.health <= 1000:
target = hero
if target:
hero.command(paladin, "cast", "heal", target)
else:
target = lowestHealthPaladin()
if target:
hero.command(paladin, "cast", "heal", target)
if paladin.health < 100:
hero.command(paladin, "shield")
if stage == 3:
pos = {"x": hero.pos.x, "y": hero.pos.y}
hero.command(paladin, "move", pos)
if stage == 4:
if warlock:
target = warlock
if target:
hero.command(paladin, "attack", target)
else:
enemy = paladin.findNearestEnemy()
if enemy:
hero.command(paladin, "attack", enemy)
if stage == 5:
target = hero.findNearestEnemy()
if target:
hero.command(paladin, "attack", target)
def commandSoldier(soldier, stage):
target = soldier.findNearestEnemy()
if target:
if stage == 3:
pos = {"x": hero.pos.x, "y": hero.pos.y}
hero.command(soldier, "move", pos)
if stage == 4:
if warlock:
target = warlock
if target:
hero.command(soldier, "attack", target)
else:
enemy = soldier.findNearestEnemy()
if enemy:
hero.command(soldier, "attack", enemy)
if stage == 5:
target = hero.findNearestEnemy()
if target:
hero.command(soldier, "attack", target)
def commandArcher(archer, stage):
target = hero.findNearestEnemy()
if target:
if stage == 3:
pos = {"x": hero.pos.x, "y": hero.pos.y}
hero.command(archer, "move", pos)
if stage == 4:
if warlock:
target = warlock
if target:
hero.command(archer, "attack", target)
else:
enemy = archer.findNearestEnemy()
if enemy:
hero.command(archer, "attack", enemy)
if stage == 5:
target = hero.findNearestEnemy()
if target:
hero.command(archer, "attack", target)
def commandFriends(stage):
friends = hero.findFriends()
for friend in friends:
if friend.type == "paladin":
commandPaladin(friend, stage)
if friend.type == "soldier":
commandSoldier(friend, stage)
if friend.type == "archer":
commandArcher(friend, stage)
while True:
catapult = hero.findNearest(hero.findByType("catapult"))
target = hero.findNearest(hero.findEnemies())
time = hero.time
summonPaladin()
if time >= 0 and time <= 54:
stage = 1
if target:
attack(target)
tower = hero.findNearest(hero.findByType("towers"))
if time >= 15.6 and time <= 54:
stage = 2
summonPaladin()
if tower:
attack(tower)
if not tower:
continue
if time >= 54 and time <= 100:
stage = 3
summonPaladin()
commandFriends(stage)
hero.moveXY(183, 15)
hero.wait(3)
hero.consecrate()
hero.wait(1)
warlock = hero.findNearest(hero.findByType("warlock"))
if time >= 100 and time <= 140:
stage = 4
if warlock:
target = warlock
if target:
commandFriends(stage)
attack(target)
if time >= 140 and time <= 190:
stage = 5
if target:
commandFriends(stage)
attack(target)
EUREKA!!! @Deadpool198 I changed the arrangement of distance and I managed to clear off the Warlocks and all the other ogres except the Chieftain and the witch! This is the first time I have seen the Chieftain in action and it does not look very nice. Thank you thank you thank you for all the help so far @Deadpool198 and @xython. Things are looking promising.
SUCCESS!!! I just commanded my troops to attack the witch and it worked! Thank you for all the help right from the start @Deadpool198 and @xython - it has really helped. Kelvintaph Glacier here we come!
This case is officially closed.
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.