Endgame code bugs?

Is there any problems with this code? (Its INSANELY long)) (Notes: I have all the equipment needed and its the warrior code

#The ULTIMATE Warrior Battle Code (Use it anywhere for combat!)
#Code explained: summons Paladins, attacks with Sword, Bashes, Power-Ups, Shields,
#uses Chain-Lighting, controls Army, allows Flags, and targets more important Ogres: 
#Witches/Catapults, then Warlocks, then Chiefs and finally shamans.

# Gear: Any Armor (preferably the best), Emperor's Gloves, Sapphire Sense stone, 
#Ezeroth's Timepiece, Boots of Leaping, Boss Star IV, Programmaticon V, Deflector, 
#Sword of the Temple Guard, Dynamic Flags or better, Order of the Paladin, Pets, and 
#Twilight Glasses

# variables: if pets, use pets = 1, if hero needs to get mushrooms, use mushrooms = 1, 
#shields = 1 if you want heart shield to work, or use shields == 0 for them not to work 
#and use brawl = 1 if it is a brawl, and if you want only paladins, tatic is "tank", 
#but if you want griffin-riders and paladins, its "ranged"
tatic = "tank"
mushrooms = 0
brawl = 0
pets = 1
go = 0
sheildtimes = 0
sheilds = 1
def itemFetch():
    while True:
        pot = pet.findNearestByType("potion")
        mushroom = pet.findNearestByType("mushroom")
        enemy2 = pet.findNearestEnemy()
        if pot:
            pet.fetch(pot)
        if mushroom and not pot:
            pet.fetch(mushroom)
def troops():
    friends = hero.findFriends()
    for friend in friends:
        if friend and friend.type == "paladin" and friend.team == hero.team:
            if friend.canCast("heal"):
                hero.command(friend, "cast","heal",hero)
            else:
                if friend.findNearestEnemy():
                    hero.command(friend, "attack",friend.findNearestEnemy() )
        if friend and friend.findNearestEnemy() and friend.type == "griffin-rider" or friend.type == "archer" or friend.type == "soldier" and friend.team== hero.team:
            if friend.findNearestEnemy():
                hero.command(friend, "attack", friend.findNearestEnemy())
    if tatic == "ranged":
        summonTypes = ["paladin","griffin-rider","griffin-rider"]
    if tatic == "tank":
        summonTypes = ["paladin","paladin"]
    summonType = summonTypes[len(hero.built) % len(summonTypes)]
    while hero.gold >= hero.costOf(summonType) and not cat:
        hero.summon(summonType)
        friends = hero.findFriends()
    for friend in friends: 
        if friend.type == "paladin" and not cat and friend.team == hero.team:
            if not friend.findNearestEnemy():
                hero.command(friend, "move", hero.pos)
            else:
                hero.command(friend, "attack", friend.findNearestEnemy())
    for friend in friends: 
        if friend.type == "griffin-rider" or friend.type == "archer" or friend.type == "soldier" and not cat and friend.team == hero.team:
            if not friend.findNearestEnemy():
                hero.command(friend, "move", hero.pos)
            else:
                hero.command(friend, "attack", friend.findNearestEnemy())
    for friend in friends:
        if friend.type == "paladin" and friend.canCast("heal") and friend.team == hero.team:
            hero.command(friend, "cast", "heal",hero)
    for friend in friends:
        if friend.type == "griffin-rider" and friend.findNearestEnemy():
            goalPoint = friend.pos
            goal = Vector.subtract(goalPoint, friend.findNearestEnemy().pos)
            goal = Vector.normalize(goal)
            goal = Vector.multiply(goal, 1)
            distance = friend.distanceTo(friend.findNearestEnemy())
            yV = Vector.subtract(friend.pos, friend.findNearestEnemy().pos)
            yV = Vector.normalize(yV)
            yV = Vector.multiply(yV, 1)
            goal = Vector.add(yV, goal)
            if goal and distance <= 10:
                hero.command(friend, "move", goal)
if pets == 1:
    pet.on( "spawn", itemFetch );
while True:
    #set up varibles
    enemy = hero.findNearestEnemy()
    flagg = hero.findFlag("green")
    friends = hero.findFriends()
    flagBlack = hero.findFlag("black")
    flagV = hero.findFlag("violet")
    troops()
    if hero.findNearest(hero.findByType("warlock")):
        if hero.isPathClear(hero.pos, hero.findNearest(hero.findByType("warlock")).pos):
            warlock = hero.findNearest(hero.findByType("warlock"))
    cat = hero.findNearest(hero.findByType("catapult"))
    if hero.findNearest(hero.findByType("witch")):
        if hero.isPathClear(hero.pos, hero.findNearest(hero.findByType("witch")).pos):
            wi = hero.findNearest(hero.findByType("witch"))
    item = hero.findNearestItem()
    if hero.findNearest(hero.findByType("chief")):
        if hero.isPathClear(hero.pos, hero.findNearest(hero.findByType("chief")).pos):
            che = hero.findNearest(hero.findByType("chief"))
    if hero.findNearest(hero.findByType("shaman")):
        if hero.isPathClear(hero.pos, hero.findNearest(hero.findByType("shaman")).pos):
            sha = hero.findNearest(hero.findByType("shaman"))
    if enemy:
        distance = hero.distanceTo(enemy)
    if brawl == 0 and hero.isReady("consecrate") and not cat and distance >= 70 and not flagg:
        hero.consecrate()
        flagg = hero.findFlag("green")
        if flagg:
            hero.pickUpFlag(flagg)
    else:
        while hero.health < hero.maxHealth and distance > 20 and brawl == 1 and not cat:
            hero.consecrate()
            enemy = hero.findNearestEnemy()
            if enemy:
                distance = hero.distanceTo(enemy)
            if distance < 20:
                break
    if enemy:
        distance = hero.distanceTo(enemy)
    shieldcount = hero.time - sheildtimes
    if enemy and shieldcount > 4 and hero.health < 3500 and sheilds == 1:
        hero.heartShield()
        sheildtimes = hero.time
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.attack(enemy)
            hero.shield()
    else:
        if sheilds != 1 and hero.health < 1000 and enemy and shieldcount > 4:
            hero.heartShield()
            sheildtimes = hero.time
            enemy = hero.findNearestEnemy()
            if enemy:
                hero.attack(enemy)
                hero.shield()
    #movement
    if item and not enemy:
        hero.moveXY(item.pos.x, item.pos.y)
    flagg = hero.findFlag("green")
    if flagg:
        hero.jumpTo(flagg)
        hero.pickUpFlag(flagg)
    if flagV:
        oof = 0
        while oof < 2:
            hero.consecrate()
            oof = oof + 0.1
        oof = 0
        hero.removeFlag(flagV)
    friends = hero.findFriends()
    if flagBlack:
        for friend in friends:
            if friend and friend.type == "soldier" or friend.type == "archer" or friend.type == "griffin-rider" or friend.type == "paladin":
                hero.command(friend, "move", flagBlack.pos)
        hero.removeFlag(flagBlack)
    # command army
    for friend in friends:
        if friend and friend.type == "paladin" and friend.team == hero.team:
            if friend.canCast("heal"):
                hero.command(friend, "cast","heal",hero)
            else:
                if friend.findNearestEnemy():
                    hero.command(friend, "attack",friend.findNearestEnemy() )
        if friend and friend.findNearestEnemy() and friend.type == "griffin-rider" or friend.type == "archer" or friend.type == "soldier" and friend.team== hero.team:
            if friend.findNearestEnemy():
                hero.command(friend, "attack", friend.findNearestEnemy())
    if tatic == "ranged":
        summonTypes = ["paladin","griffin-rider","griffin-rider"]
    if tatic == "tank":
        summonTypes = ["paladin","paladin"]
    summonType = summonTypes[len(hero.built) % len(summonTypes)]
    while hero.gold >= hero.costOf(summonType) and not cat:
        hero.summon(summonType)
        friends = hero.findFriends()
    for friend in friends: 
        if friend.type == "paladin" and not cat and friend.team == hero.team:
            if not friend.findNearestEnemy():
                hero.command(friend, "move", hero.pos)
            else:
                hero.command(friend, "attack", friend.findNearestEnemy())
    for friend in friends: 
        if friend.type == "griffin-rider" or friend.type == "archer" or friend.type == "soldier" and not cat and friend.team == hero.team:
            if not friend.findNearestEnemy():
                hero.command(friend, "move", hero.pos)
            else:
                hero.command(friend, "attack", friend.findNearestEnemy())
    for friend in friends:
        if friend.type == "paladin" and friend.canCast("heal") and friend.team == hero.team:
            hero.command(friend, "cast", "heal",hero)
    for friend in friends:
        if friend.type == "griffin-rider" and friend.findNearestEnemy():
            goalPoint = friend.pos
            goal = Vector.subtract(goalPoint, friend.findNearestEnemy().pos)
            goal = Vector.normalize(goal)
            goal = Vector.multiply(goal, 1)
            distance = friend.distanceTo(friend.findNearestEnemy())
            yV = Vector.subtract(friend.pos, friend.findNearestEnemy().pos)
            yV = Vector.normalize(yV)
            yV = Vector.multiply(yV, 1)
            goal = Vector.add(yV, goal)
            if goal and distance <= 10:
                hero.command(friend, "move", goal)
    #attack special enemy
    if hero.findNearest(hero.findByType("warlock",hero.findEnemies())):
        if hero.isPathClear(hero.pos, hero.findNearest(hero.findByType("warlock")).pos):
            warlock = hero.findNearest(hero.findByType("warlock"))
    if hero.findNearest(hero.findByType("catapult",hero.findEnemies())):
        if hero.isPathClear(hero.pos, hero.findNearest(hero.findByType("catapult",hero.findEnemies()))):
            cat = hero.findNearest(hero.findByType("catapult"))
    if hero.findNearest(hero.findByType("witch",hero.findEnemies())):
        if hero.isPathClear(hero.pos, hero.findNearest(hero.findByType("witch")).pos):
            wi = hero.findNearest(hero.findByType("witch"))
    item = hero.findNearestItem()
    if hero.findNearest(hero.findByType("chief",hero.findEnemies())):
        if hero.isPathClear(hero.pos, hero.findNearest(hero.findByType("chief")).pos):
            che = hero.findNearest(hero.findByType("chief"))
    if hero.findNearest(hero.findByType("shaman",hero.findEnemies())):
        if hero.isPathClear(hero.pos, hero.findNearest(hero.findByType("shaman")).pos):
            sha = hero.findNearest(hero.findByType("shaman"))
    if hero.findNearest(hero.findByType("skeleton",hero.findEnemies())):
        if hero.isPathClear(hero.pos, hero.findNearest(hero.findByType("skeleton")).pos):
            skele = hero.findNearest(hero.findByType("skeleton"))
    if cat and cat.health >= 1:
        hero.attack(cat)
    if wi and wi.health >= 1:
        hero.attack(wi)
    if warlock and not wi and not che and warlock.health >= 1:
        hero.attack(warlock)
    if che and not wi and che.health >= 1:
        hero.attack(che)
    if sha and not wi and not che and sha.health >= 1:
        hero.attack(sha)
    #attack normal
    enemy = hero.findNearestEnemy()
    if enemy:
        distance = hero.distanceTo(enemy)
    if enemy and hero.isPathClear(hero.pos, enemy.pos) and not cat and not warlock and not wi and not che and enemy.type != "sand-yak":
        enemy = hero.findNearestEnemy()
        if hero.canCast("chain-lightning", enemy):
            enemy = hero.findNearestEnemy()
            if enemy:
                hero.cast("chain-lightning", enemy)
                
        else:
            enemy = hero.findNearestEnemy()
            if hero.isReady("bash"):
                enemy = hero.findNearestEnemy()
                if enemy:
                    hero.bash(enemy)
                    
                hero.shield()
            else: 
                if hero.isReady("power-up"):
                    enemy = hero.findNearestEnemy()
                    if enemy:
                        hero.attack(enemy)
                        hero.powerUp()
                enemy = hero.findNearestEnemy()
                if enemy:
                    hero.attack(enemy)
                hero.shield()
    #command army agian
    for friend in friends:
        if friend and friend.type == "paladin" and friend.team == hero.team:
            if friend.canCast("heal"):
                hero.command(friend, "cast","heal",hero)
            else:
                if friend.findNearestEnemy():
                    hero.command(friend, "attack",friend.findNearestEnemy() )
        if friend and friend.findNearestEnemy() and friend.type == "griffin-rider" or friend.type == "archer" or friend.type == "soldier" and friend.team== hero.team:
            if friend.findNearestEnemy():
                hero.command(friend, "attack", friend.findNearestEnemy())
    if tatic == "ranged":
        summonTypes = ["paladin","griffin-rider","griffin-rider"]
    if tatic == "tank":
        summonTypes = ["paladin","paladin"]
    summonType = summonTypes[len(hero.built) % len(summonTypes)]
    while hero.gold >= hero.costOf(summonType) and not cat:
        hero.summon(summonType)
        friends = hero.findFriends()
    for friend in friends: 
        if friend.type == "paladin" and not cat and friend.team == hero.team:
            if not friend.findNearestEnemy():
                hero.command(friend, "move", hero.pos)
            else:
                hero.command(friend, "attack", friend.findNearestEnemy())
    for friend in friends: 
        if friend.type == "griffin-rider" or friend.type == "archer" or friend.type == "soldier" and not cat and friend.team == hero.team:
            if not friend.findNearestEnemy():
                hero.command(friend, "move", hero.pos)
            else:
                hero.command(friend, "attack", friend.findNearestEnemy())
    for friend in friends:
        if friend.type == "paladin" and friend.canCast("heal") and friend.team == hero.team:
            hero.command(friend, "cast", "heal",hero)
    for friend in friends:
        if friend.type == "griffin-rider" and friend.findNearestEnemy():
            goalPoint = friend.pos
            goal = Vector.subtract(goalPoint, friend.findNearestEnemy().pos)
            goal = Vector.normalize(goal)
            goal = Vector.multiply(goal, 1)
            distance = friend.distanceTo(friend.findNearestEnemy())
            yV = Vector.subtract(friend.pos, friend.findNearestEnemy().pos)
            yV = Vector.normalize(yV)
            yV = Vector.multiply(yV, 1)
            goal = Vector.add(yV, goal)
            if goal and distance <= 10:
                hero.command(friend, "move", goal)
    hero.moveXY(hero.pos.x, hero.pos.y)

Could I please get a level link and see a pic of your gear? That is so I can help you out a bit better.

1 Like

Its not for a level in particular, its just a battle code :slight_smile:
Also, for gear just go to gems help for endgame (in my profile). I have boots of leaping and the order of the paladin + dynamic flags though.

Is this a level?
summit’s gate?
I use the simular code to beat summit’s gate lol

It was code to beat summits gate, but then I just used it everywhere :laughing:

Pls don’t share the code
@Bolt_coy
Pls delete it right now!!

Deleting it right now won’t do much, people can just see the edits -_- and plus, this code would only work with specific equipment

and we cannot see the gear. SO that is good.

Why? (20 Chars suck)

Because, people can just take your solution and then bam they beat level and they didn’t even have to try.

1 Like

By the way, it doesn’t even beat summits gate anymore :rofl:

1 Like

Also, it requires you to get boss star IV, making the code to beat summits gate useless

1 Like

You can just do Defiler before beating the gate, but yeah, since Defiler’s a lot harder than gate

1 Like