I think there is a bug in my archers, I try different methods but nothing works after I kill the witch they just stand still.
# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!
#Define friend
friend = hero.findFriends()
friends = hero.findFriends()
#Define all enemy
witch = hero.findByType("witch",friends[0].findEnemies())[0]
skeleton = hero.findByType("skeleton",friends[0].findEnemies())[0]
ogre = hero.findByType("ogre",friends[0].findEnemies())[0]
enemy = hero.findNearestEnemy()
#Command Paladin to Cure
if friend.type=="paladin":
if friend.canCast("heal") and friend.health<300:
hero.command(friend,"cast","heal",friend)
else:
pass
#Command friend to leave
def witchDead():
if witch.health <0:
if friend.type=="archer":
hero.command(friend, "move", {"x": 31, "y": 59})
hero.command(friend, "move",{"x": 65, "y": 57})
hero.command(friend, "move",{"x": 65, "y": 40})
hero.command(friend, "move",{"x": 78, "y": 40})
#Command archer to kill the witch
for friend in friends:
if witch and witch.health>0:
if friend.type=="archer":
hero.command(friend,"attack",witch)
else:
witchDead()
#Command paladin to atack skeletons
if skeleton and skeleton.health>0:
if friend.type=="paladin":
hero.command(friend,"attack", skeleton)
else:
pass
#Command soldier to atack ogres
if ogre and ogre.health>0:
if friend.type=="soldier":
hero.command(friend, "attack", ogre)
else:
hero.command(friend, "attack", enemy)
#Command Paladin to Cure
#Command hero to move
def move():
point1 = { "x" : 69, "y" : 15 }
point2 = { "x" : 37, "y" : 16 }
while hero.pos.x<69:
hero.move( point1)
while hero.pos.x>37:
hero.wait(2)
hero.move( point2 )
hero.moveXY(78, 14)
#Command hero move
move()
What if the witch’s health equals exactly zero?
if friend.type=="archer":
hero.command(friend, "move", {"x": 31, "y": 59})
hero.command(friend, "move",{"x": 65, "y": 57})
hero.command(friend, "move",{"x": 65, "y": 40})
hero.command(friend, "move",{"x": 78, "y": 40})
Do you really believe this is working?
Even if its not if i try to command in any other way the archer it stands still
Example:
for friend in friends:
if witch and witch.health>0:
if friend.type=="archer":
hero.command(friend,"attack",witch)
else:
hero.command(friend, "move", {"x": 30, "y": 38})
im telling the archer to kill the witch if he is there and if he haves health if that is not true to move to the place i marked, the with is always there and is going to have health until it dies once he is dead wich the archers manage to do he moves.
I suppose you want this:
for friend in friends:
if friend.type=="archer":
if witch and witch.health>0:
hero.command(friend,"attack",witch)
else:
hero.command(friend, "move", {"x": 30, "y": 38})
i restart the level and tried the code and it worked, then i put it in my code and it dosent work
why?
# You can find friends through walls, but not enemies.
# Watch out for smooth, frictionless ice patches!
#Define friend
friend = hero.findFriends()
friends = hero.findFriends()
#Define all enemy
witch = hero.findByType("witch",friends[0].findEnemies())[0]
skeleton = hero.findByType("skeleton",friends[0].findEnemies())[0]
ogre = hero.findByType("ogre",friends[0].findEnemies())[0]
enemy = hero.findNearestEnemy()
#Command Paladin to Cure
if friend.type=="paladin":
if friend.canCast("heal") and friend.health<300:
hero.command(friend,"cast","heal",friend)
else:
pass
#Command friend to leave
#Command archer to kill the witch
for friend in friends:
if friend.type=="archer":
if witch and witch.health>0:
hero.command(friend,"attack",witch)
else:
hero.command(friend, "move", {"x": 30, "y": 38})
#Command paladin to atack skeletons
if skeleton and skeleton.health>0:
if friend.type=="paladin":
hero.command(friend,"attack", skeleton)
else:
pass
#Command soldier to atack ogres
if ogre and ogre.health>0:
if friend.type=="soldier":
hero.command(friend, "attack", ogre)
else:
pass
#Command Paladin to Cure
#Command hero to move
def move():
point1 = { "x" : 69, "y" : 15 }
point2 = { "x" : 37, "y" : 16 }
while hero.pos.x<69:
hero.move( point1)
while hero.pos.x>37:
hero.wait(2)
hero.move( point2 )
hero.moveXY(78, 14)
#Command hero move
move()