Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Summit's Gate help! [Python]

#1
# Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
def attack():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

def commandArcher(archer):
    for friend in hero.findByType("archer"):
        tower = hero.findByType("tower")
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)

def commandSoldier(soldier):
    friends = hero.findFriends()
    for friend in hero.findByType("soldier"):
        catapult = hero.findByType("catapult")
        if catapult:
            hero.command(friend, "move", {'x': catapult.pos.x, 'y': catapult.pos.y})

def commandPaladin(paladin):
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    friend = hero.findNearest(friends)
    if paladin.canCast("heal") and hero.health <= 1000:
        hero.command(paladin,"cast" "heal", hero)
    elif enemy:
        hero.command(paladin, "attack", enemy)

def commandFriends():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "paladin":
            commandPaladin(friend)
        if friend.type == "archer":
            commandArcher(friend)
        if friend.type == "soldier":
            commandSoldier(friend)

while True:
    commandFriends()
    attack()

I need some help about this, my soldier didn’t walk to the catapult and it’s error :frowning: can someone help me please?

0 Likes

#2

When you use hero.findByType() you get an array which doesn’t give you the pos you need.

catapult = hero.findByType("catapult") # returns an array
# add a .findNearest before to isolate the closest catapult to the friend
catapult = friend.findNearest(hero.findByType("catapult"))

1 Like

#3

Thanks that’s work!, but

def commandPaladin(paladin):
    enemy = hero.findNearestEnemy()
    friends = hero.findFriends()
    for friend in friends:
        if paladin.canCast("heal") and hero.health <= 1000:
            hero.command(paladin, "cast" "heal", hero)
        elif enemy:
            hero.command(paladin, "attack", enemy)

It’s error the paladin didn’t heal me

0 Likes

#4

I found it!

if paladin.canCast("heal") and hero.health <= 1000:
            hero.command(paladin, "cast" "heal", hero)

I forgot to put the “,”

0 Likes