Kelvintaph burgler help!


#1

can someone help me out in kelvintaph burgler
here is my code:

coord1 = [0, 0]
coord2 = [0, 0]

def moveTo(position, fast = True):
if(hero.isReady(“jump”) and fast):
hero.jumpTo(position)
else:
hero.move(position)

summonTypes = [‘soldier’]

def summonTroops():
type = summonTypes[len(hero.built)%len(summonTypes)]
if hero.gold > hero.costOf(type):
hero.summon(type)

def commandTroops():
chieftain = hero.findNearest(hero.findByType(‘chieftain’))
for index, friend in enumerate(hero.findFriends()):
if chieftain and friend.type != ‘paladin’:
continue
if witch and friend.type != ‘paladin’:
continue
if chieftain and chieftain.pos.x<57 and chieftain.pos.x> 43:
hero.command(friend, “move”, {‘x’:25, ‘y’:48})
elif not chieftain and friend.pos.x<40:
hero.command(friend, “move”, {‘x’:51, ‘y’:51})
elif friend.type == ‘paladin’:
CommandPaladin(friend)
elif friend.type == ‘soldier’:
if friend.pos.y>30:
CommandSoldier(friend)
else:
KillRobots(friend)
else:
CommandArcher(friend)

def CommandPaladin(paladin):
if(paladin.canCast(“heal”) and not chieftain):
target = lowestHealthFriend()
if target:
hero.command(paladin, “cast”, “heal”, target)
elif(paladin.health<100):
hero.command(paladin, “shield”)
else:
if witch:
hero.command(paladin, “attack”, witch)
elif(chieftain):
hero.command(paladin, “attack”, chieftain)
else:
hero.command(paladin, “move”, {‘x’:78, ‘y’:40})

def CommandSoldier(soldier):
if witch:
hero.command(soldier, “attack”, witch)
else:
hero.command(soldier, “move”, {‘x’:78, ‘y’:40})

def CommandArcher(soldier):
if witch:
hero.command(soldier, “attack”, witch)
else:
hero.command(soldier, “move”, {‘x’:78, ‘y’:40})

def KillRobots(soldier):
robot = hero.findNearest(hero.findEnemies())
if robot:
hero.command(soldier, “attack”, robot)

def lowestHealthFriend():
lowestHealth = 99999
lowestFriend = None
friends = hero.findFriends()
for friend in friends:
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend
return lowestFriend

def findTheY(x1, x2, y1, y2, x):
if(y2!=y1):
y = (x - x1)/(x2 - x1)*(y2 - y1) + y1
else:
y = y1
return y

def findTheMiddle(pos1, pos2):
return {‘x’:(pos1.x+pos2.x)/2,‘y’:(pos1.y+pos2.y)/2}

loop:
witch = hero.findNearest(hero.findByType(‘witch’))
chieftain = hero.findNearest(hero.findByType(‘chieftain’))
if witch or chieftain:
RunFrom()

commandTroops()

#2

coord1 = [0, 0]
coord2 = [0, 0]

def moveTo(position, fast = True):
    if(hero.isReady("jump") and fast):
        hero.jumpTo(position)
    else:
        hero.move(position)

summonTypes = ['soldier']

def summonTroops():
    type = summonTypes[len(hero.built)%len(summonTypes)]
    if hero.gold > hero.costOf(type):
        hero.summon(type)

def commandTroops():
    chieftain = hero.findNearest(hero.findByType('chieftain'))
    for index, friend in enumerate(hero.findFriends()):
        if chieftain and friend.type != 'paladin':
            continue
        if witch and friend.type != 'paladin':
            continue
        if chieftain and chieftain.pos.x<57 and chieftain.pos.x> 43:
            hero.command(friend, "move", {'x':25, 'y':48})
        elif not chieftain and friend.pos.x<40:
            hero.command(friend, "move", {'x':51, 'y':51})
        elif friend.type == 'paladin':
            CommandPaladin(friend)
        elif friend.type == 'soldier':
            if friend.pos.y>30:
                CommandSoldier(friend)
            else:
                KillRobots(friend)
        else:
            CommandArcher(friend)

def CommandPaladin(paladin):
    if(paladin.canCast("heal") and not chieftain):
        target = lowestHealthFriend()
        if target:
            hero.command(paladin, "cast", "heal", target)
    elif(paladin.health<100):
        hero.command(paladin, "shield")
    else:
        if witch:
            hero.command(paladin, "attack", witch)
        elif(chieftain):
            hero.command(paladin, "attack", chieftain)
        else:
            hero.command(paladin, "move", {'x':78, 'y':40})

def CommandSoldier(soldier):
    if witch:
        hero.command(soldier, "attack", witch)
    else:
        hero.command(soldier, "move", {'x':78, 'y':40})

def CommandArcher(soldier):
    if witch:
        hero.command(soldier, "attack", witch)
    else:
        hero.command(soldier, "move", {'x':78, 'y':40})

def KillRobots(soldier):
    robot = hero.findNearest(hero.findEnemies())
    if robot:
        hero.command(soldier, "attack", robot)

def lowestHealthFriend():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    for friend in friends:
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend
    return lowestFriend

def findTheY(x1, x2, y1, y2, x):
    if(y2!=y1):
        y = (x - x1)/(x2 - x1)*(y2 - y1) + y1
    else:
        y = y1
    return y

def findTheMiddle(pos1, pos2):
    return {'x':(pos1.x+pos2.x)/2,'y':(pos1.y+pos2.y)/2}

loop:
    witch = hero.findNearest(hero.findByType('witch'))
    chieftain = hero.findNearest(hero.findByType('chieftain'))
    if witch or chieftain:
        RunFrom()
    else:
        
    commandTroops()


#3

What goes wrong on your code?


#4

I’m trying to figure out how to get the paladin to move ahead to lure the chieftain into attacking the ogre but i keep failing at it


#5

Sorry i meant ice yak