Haris
November 13, 2021, 10:33am
1
Rider not moving or attack
`summonTypes = ['paladin']
def attack(enemy):
if enemy:
while (enemy.health > 0):
if (hero.distanceTo(enemy) > 10):
hero.move(enemy.pos)
elif (hero.isReady("bash")):
hero.bash(enemy)
elif (hero.canCast('chain-lightning', enemy)):
hero.cast('chain-lightning', enemy)
else:
hero.attack(enemy)
def summonTroops():
type = summonTypes[len(hero.built) % len(summonTypes)]
if hero.gold > hero.costOf(type):
hero.summon(type)
def commandTroops():
for index, friend in enumerate(hero.findFriends()):
if friend.type == 'paladin':
CommandPaladin(friend)
def CommandPaladin(paladin):
if (paladin.canCast("heal") and hero.health < hero.maxHealth * 0.6):
hero.command(paladin, "cast", "heal", hero)
else:
hero.command(paladin, "defend", hero)
def collectItems():
item = hero.findNearestItem()
while item:
hero.move(item.pos)
item = hero.findNearestItem()
hero.moveXY(55, 10)
hero.wait(2)
attack(hero.findNearestEnemy())
collectItems()
hero.moveXY(55, 33)
hero.moveXY(49, 37)
hero.moveXY(19, 40)
for i in range(1, 20):
summonTroops()
commandTroops()
hero.moveXY(55, 48)
while True:
attack(hero.findNearestEnemy())
commandTroops()
collectItems()`
Haris
November 13, 2021, 10:50am
2
need help quickly 20 characters
its because you do not have a commanding line for griffins
there is also a apostrophy at the start—>
2 Likes
Haris
November 14, 2021, 8:13am
5
def attack(enemy):
if enemy:
while (enemy.health > 0):
if (hero.distanceTo(enemy) > 10):
hero.move(enemy.pos)
elif (hero.isReady("bash")):
hero.bash(enemy)
elif (hero.canCast('chain-lightning', enemy)):
hero.cast('chain-lightning', enemy)
else:
hero.attack(enemy)
summonTypes = ['griffin-rider']
def summonTroops():
type = summonTypes[len(hero.built)%len(summonTypes)]
if hero.gold >= hero.costOf(type):
hero.summon(type)
def collectItems():
item = hero.findNearestItem()
while item:
hero.move(item.pos)
item = hero.findNearestItem()
def comGrif(griff):
enemy = hero.findNearestEnemy()
if enemy:
hero.command(griff, "attack", enemy)
else:
hero.move(hero.pos)
def commandTroops():
for index, friend in enumerate(hero.findFriends()):
if friend.type == 'griffin-rider':
comGrif(friend)
hero.moveXY(53, 14)
hero.wait(2)
attack(hero.findNearestEnemy())
collectItems()
hero.moveXY(55, 33)
hero.moveXY(49, 37)
hero.moveXY(19, 40)
for i in range(1, 20):
summonTroops()
commandTroops()
hero.moveXY(23, 38)
while True:
commandTroops()
collectItems()
still not working…
you’ve defined the function to command your griffins but you aren’t running the function in the while True
loop
Haris
November 18, 2021, 3:44pm
7
i already put it in command troops and it already in while true
2 Likes
Here’s my code:
def commandArcher():
friends = hero.findFriends()
enemy = hero.findNearestEnemy()
for friend in friends:
if friend and friend.type == “griffin-rider”:
hero.command(friend, “attack”, enemy)
hero.buildXY(“fire-trap”, 51, 13)
hero.buildXY(“fire-trap”, 51, 13)
hero.moveXY(30, 8)
hero.moveXY(60, 22)
hero.moveXY(48, 7)
hero.moveXY(48, 39)
hero.moveXY(56, 50)
hero.buildXY(“fire-trap”, 67, 58)
hero.moveXY(51, 44)
hero.moveXY(19, 40)
hero.moveXY(51, 44)
hero.moveXY(56, 50)
hero.moveXY(62, 55)
hero.moveXY(60, 58)
while True:
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
if hero.gold >= hero.costOf("griffin-rider"):
hero.summon("griffin-rider")
for friend in friends:
commandArcher()
if hero.isReady("bash"):
hero.bash(enemy)
else:
hero.shield()
My code is right, but I can’t beat Rotting General
Hi, welcome to the forums, could you please format your code correctly by putting the ``` at the start?
1 Like
def commandArcher():
friends = hero.findFriends()
enemy = hero.findNearestEnemy()
for friend in friends:
if friend and friend.type == "griffin-rider":
hero.command(friend, "attack", enemy)
hero.buildXY("fire-trap", 51, 13)
hero.buildXY("fire-trap", 51, 13)
hero.moveXY(30, 8)
hero.moveXY(60, 22)
hero.moveXY(48, 7)
hero.moveXY(48, 39)
hero.moveXY(56, 50)
hero.buildXY("fire-trap", 62, 54)
hero.moveXY(51, 44)
hero.moveXY(19, 40)
hero.moveXY(51, 44)
hero.moveXY(56, 50)
hero.moveXY(62, 55)
hero.moveXY(60, 58)
while True:
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
if hero.gold >= hero.costOf("griffin-rider"):
hero.summon("griffin-rider")
for friend in friends:
commandArcher()
if enemy:
if hero.isReady("bash"):
hero.bash(enemy)
else:
hero.move(enemy.pos)
hero.buildXY("fire-trap", hero.pos.x, hero.pos.y)