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

Need Help on Kelvintaph Burgler (Help Please) [SOLVED]

I want the paladin to move near the chieftan and come back to the other side but she only stays on one side.
Here is my code:

distracted_chieftan = False
def commandPaladin(friend):
    if not distracted_chieftan:
        hero.command(friend, "move", Vector(53,50))
        dodge()
        dodge()
        dodge()
        dodge()
        distracted_chieftan = True
    if distracted_chieftan:
        hero.command(friend, "move", Vector(32,50))
def almostEqual(a, b):
    return a-4 < b < a+4
def dodge():
    missles = hero.findEnemyMissiles()
    if len(missles) != 0:
        missle = hero.findNearest(missles)
        if missle:
            distance = hero.distanceTo(missle)
            if distance < 5:
                if almostEqual(hero.pos.y, 14):
                    hero.moveXY(hero.pos.x, hero.pos.y-8)
                elif almostEqual(hero.pos.y, 6):
                    hero.moveXY(hero.pos.x, hero.pos.y+8)
while True:
    dodge()
    paladin = hero.findByType("paladin")[0]
    commandPaladin(paladin)

Do you want this?

def commandPaladin(friend):
    if friend:
        if not distracted_chieftan:
            hero.command(friend, "move", Vector(53,50))
            # dodge()...
            distracted_chieftan = True
        elif distracted_chieftan:
            hero.command(friend, "move", Vector(32,50))

I like the way you move :slight_smile:

1 Like

Well, but he won’t move to the other side.

I changed my code with different variables:

# What eldritch artifacts are these? Don't let them blast you!
# The ice gate will open when both ogres are defeated.
dis = False
def commandPaladin(friend):
    if not dis:
        hero.command(friend, "move", Vector(53,50))
        distracted_chieftan = True
    if dis:
        hero.command(friend, "move", Vector(32,50))
def almostEqual(a, b):
    return a-4 < b < a+4
def dodge():
    missles = hero.findEnemyMissiles()
    if len(missles) != 0:
        missle = hero.findNearest(missles)
        if missle:
            distance = hero.distanceTo(missle)
            if distance < 5:
                if almostEqual(hero.pos.y, 14):
                    hero.moveXY(hero.pos.x, hero.pos.y-8)
                elif almostEqual(hero.pos.y, 6):
                    hero.moveXY(hero.pos.x, hero.pos.y+8)
while True:
    dodge()
    paladin = hero.findByType("paladin")[0]
    commandPaladin(paladin)

but now he won’t move back to the other side.

You want the paladin to turn toward the initial position as in this animation?

Actually, I’ve already changed my code to work. Thanks for all the help!

I’m curious how you solved it
I tried this code and it failed:

distracted_chieftan = False
pos1 = Vector(53,50)
pos2 = Vector(32,50)
def commandPaladin(friend):
    if friend:
        if not distracted_chieftan:
            hero.command(friend, "move", pos1)
            if friend.distanceTo(pos1) == 0:
                distracted_chieftan = True
        if distracted_chieftan:
            hero.command(friend, "move", pos2)
while True:
    dodge()
    friend = hero.findByType("paladin")[0]
    commandPaladin(friend)

but after inserting the function code into the while true loop

distracted_chieftan = False
pos1 = Vector(53,50)
pos2 = Vector(32,50)
while True:
    dodge()
    friend = hero.findByType("paladin")[0]
    if not distracted_chieftan:
        hero.command(friend, "move", pos1)
        if friend.distanceTo(pos1) == 0:
            distracted_chieftan = True
    if distracted_chieftan:
        hero.command(friend, "move", pos2)

the code worked

What is your solution? Why using this function doesn’t work?

I solved it. Here’s my code:

def findEnemy(id):
    for enemy in hero.findEnemies():
        if enemy.id == id:
            return enemy
    return None

dis = False
def commandPaladinStage1(friend):
    if not dis:
        hero.command(friend, "move", Vector(53,50))
        cheiftain = findEnemy("Oniko")
        if cheiftain and cheiftain.target == friend:
            dis = True
    if dis:
        hero.command(friend, "move", Vector(37,41))
def almostEqual(a, b):
    return a-4 < b < a+4
def almostEqual2(a, b):
    return a-0.6 < b < a+0.6
def dodge():
    missles = hero.findEnemyMissiles()
    if len(missles) != 0:
        missle = hero.findNearest(missles)
        if missle:
            distance = hero.distanceTo(missle)
            if distance < 6:
                if almostEqual(hero.pos.y, 14):
                    hero.moveXY(hero.pos.x, hero.pos.y-8)
                elif almostEqual(hero.pos.y, 6):
                    hero.moveXY(hero.pos.x, hero.pos.y+8)
stage = 1
while True:
    dodge()
    if stage == 1:
        paladin = hero.findByType("paladin")[0]
        commandPaladinStage1(paladin)
    if len(hero.findByType("chieftain")) == 0:
        stage = 2
    

I haven’t completed it yet but I hope I will.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.