[SOLVED] Help! Restless Dead [Python]

def summonArcher():
    if hero.gold > hero.costOf("archer"):
        hero.summon("archer")
def commandArcher():
    friends = hero.findFriends()
    enemy = hero.findNearestEnemy
    for friend in friends:
        if friend and friend.type == "archer":
            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.pos == {'x':56, 'y':50}:
        
        if hero.gold > hero.costOf("archer"):
            summonArcher()
        for friend in friends:
            
            commandArcher()
    
    if hero.isReady("bash"):
        hero.bash(enemy)
    else:
        hero.shield()
        

It still doesn’t summon Archers
Lydia

Delete the summonArcher function. you do not need it. then by the if hero > hero.costOf(“archer”) put this:

hero.summon("archer").

This does not matter much, but put if hero.gold >= hero.costOf("archer") instead of this:

Jonathan

def commandArcher():
    friends = hero.findFriends()
    enemy = hero.findNearestEnemy()
    for friend in friends:
        if friend and friend.type == "archer":
            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("archer"):
        hero.summon("archer")
        for friend in friends:
            
            commandArcher()
    
    if hero.isReady("bash"):
        hero.bash(enemy)
    else:
        hero.shield()
        

Now I summon some, but it is when all of the skeletons come piling out.
Lydia

@Lydia_Song Sorry I cannot help you that much, but try and check out this topic: Restless dead - 'I can't get there'
It might help you

Jonathan

def summon():
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
    else:
        break

def command():
    friends = hero.findFriends()
    
    
    for friend in friends:
        enemyF = friend.findNearestEnemy()
        if enemyF:
            
            hero.command(friend, "attack", enemyF)
        if not enemyF:
            break
        

def friendMove():
    friends = hero.findFriends()
    for friend in friends:
        hero.command(friend, "move", {'x':45, 'y':39})
        

def attack():
    enemy = hero.findNearestEnemy()
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        else:
            
            hero.attack(enemy)
            

def collect():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
    else:
        break




while True:
    friends = hero.findFriends()
    yeti = hero.findByType("yeti-cub")[0]
    item = hero.findNearestItem()
    
    enemy = hero.findNearestEnemy()
    if hero.gold > hero.costOf("soldier"):
        summon()
    for friend in friends:
        enemyF = friend.findNearestEnemy()
        if enemyF:
            command()
        if not enemyF:
            friendMove()
    if enemy:
        
        enemy = hero.findNearestEnemy()
        
        if hero.isReady("bash"):
            hero.bash(enemy)
        else:
            
            hero.attack(enemy)
            
    if item:
        collect()
    hero.move({'x':19, 'y':40})
    hero.move({'x':51, 'y':44})

@xython Can you make a GIF for me using this code? This is not a working code, but when you run it, it’s really funny.
hero.go(brrrrr)
Lydia

Maybe you don’t need

if condition:
    code
else:
    break

in your code. You saw that there is no need in this on previous level.

def summon():
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
    

def command():
    friends = hero.findFriends()
    
    
    for friend in friends:
        enemyF = friend.findNearestEnemy()
        if enemyF:
            
            hero.command(friend, "attack", enemyF)
        
        

def friendMove():
    friends = hero.findFriends()
    for friend in friends:
        hero.command(friend, "move", {'x':45, 'y':39})
        

def attack():
    enemy = hero.findNearestEnemy()
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        else:
            
            hero.attack(enemy)
            

def collect():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
    




while True:
    friends = hero.findFriends()
    yeti = hero.findByType("yeti-cub")[0]
    item = hero.findNearestItem()
    
    enemy = hero.findNearestEnemy()
    if hero.gold > hero.costOf("soldier"):
        summon()
    for friend in friends:
        enemyF = friend.findNearestEnemy()
        if enemyF:
            command()
        if not enemyF:
            friendMove()
    if enemy:
        
        enemy = hero.findNearestEnemy()
        
        if hero.isReady("bash"):
            hero.bash(enemy)
        else:
            
            hero.attack(enemy)
            
    if item:
        collect()
    hero.move({'x':19, 'y':40})
    hero.move({'x':51, 'y':44})

My hero still goes brrrrrr.
Lydia

You’ve got some double code going on here. In your while True loop you use a for loop to command your friends, then you use the command() function which also has a for loop. I think you need to chose one of the places to use so you only have one for loop.
You also have the same code twice for the collect() function.
Danny

2 Likes
def summon():
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")

def command():
    friends = hero.findFriends()
    for friend in friends:
        enemyF = friend.findNearestEnemy()
        if enemyF:
            hero.command(friend, "attack", enemyF)

def friendMove():
    friends = hero.findFriends()
    for friend in friends:
        hero.command(friend, "move", {'x':45, 'y':39})

def attack():
    enemy = hero.findNearestEnemy()
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        else:
            hero.attack(enemy)

def collect():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)

while True:
    friends = hero.findFriends()
    item = hero.findNearestItem()
    enemy = hero.findNearestEnemy()
    if hero.gold > hero.costOf("soldier"):
        summon()
    command()
    friendMove()
    if enemy:
        attack()
        
    collect()
    hero.move({'x':19, 'y':40})
    hero.move({'x':51, 'y':44})

Danny, I tried doing what you said, but my hero still goes brrrrrrr.
Lydia

Ok, I think it’s time for a bit of a structural overhaul of your code. (sorry!) Let me explain:

The main problem is the hero.move()s. Your hero is going to do that every single loop, but there’s also an item (the gold), which you’re hero will move to, meaning your hero is making loads of tiny movements and not going anywhere.
A simple solution would be to remove the moves and put an else in the collect function with something like:
elif time < 50:
hero.move(somewhere).
Tacticwise, just use archers and place them further away from the entrance to the skeletons. Then take on the skeletons first (move away from the x after triggering the ritual, but before the skells appear), and your archers will decimate the skells. Make sure you don’t get stuck on the rails later in the level.
Danny

3 Likes
def onSpawn():
    if pet.isReady("shape-shift"):
        pet.shapeShift() 

def move():
    hero.moveXY(19, 40)

def summon():
    if hero.gold > hero.costOf("archer"):
        hero.summon("archer")

def command():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            enemyF = friend.findNearestEnemy()
            if enemyF:
                hero.command(friend, "attack", enemyF)

def friendMove():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            hero.command(friend, "move", {'x':44, 'y':38})

def attack():
    enemy = hero.findNearestEnemy()
    hero.moveXY(56, 50)
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        if hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        else:
            hero.attack(enemy)

def collect():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)

while True:
    friends = hero.findFriends()
    item = hero.findNearestItem()
    enemy = hero.findNearestEnemy()
    pet.on("spawn", onSpawn)
    pet.moveXY(60, 56)
    if hero.gold > hero.costOf("soldier"):
        summon()
    command()
    friendMove()
    move()
    if enemy:
        attack()
    while hero.time < 35:
        collect()
    

But now, it says

Code never finished

Lydia

Maybe it isn’t about slow code, but I think you don’t have to write
if hero.gold > hero.costOf("soldier"):
here.

I removed the if statement, but it is still the same.
Lydia

Good idea, but while seems to break coco. Just use if hero.time < 35:, you’re already inside a while True loop so that will work fine.
Danny

1 Like
def onSpawn():
    if pet.isReady("shape-shift"):
        pet.shapeShift() 

def move():
    hero.moveXY(19, 40)

def summon():
    if hero.gold > hero.costOf("archer"):
        hero.summon("archer")

def command():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            enemyF = friend.findNearestEnemy()
            if enemyF:
                hero.command(friend, "attack", enemyF)

def friendMove():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            hero.command(friend, "move", {'x':44, 'y':38})

def attack():
    enemy = hero.findNearestEnemy()
    hero.moveXY(56, 50)
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        if hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        else:
            hero.attack(enemy)

def collect():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)

while True:
    friends = hero.findFriends()
    item = hero.findNearestItem()
    enemy = hero.findNearestEnemy()
    pet.on("spawn", onSpawn)
    pet.moveXY(60, 56)
    summon()
    command()
    friendMove()
    move()
    if enemy:
        attack()
    if hero.time < 35:
        collect()
    

but my hero just goes back at forth from the red x to the entrance of the tomb, without collecting anything, also the archers do not attack. My hero attacks sometimes, but most of the time, he just walks.
Lydia

That’s because your two moveXY statements are endless. You need some ifs in front of them
Danny

def onSpawn():
    if pet.isReady("shape-shift"):
        pet.shapeShift() 

def move():
    hero.move({'x':19, 'y':40})
    hero.move({'x':56, 'y':51})

def summon():
    if hero.gold > hero.costOf("archer"):
        hero.summon("archer")

def command():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            enemyF = friend.findNearestEnemy()
            if enemyF:
                hero.command(friend, "attack", enemyF)
            else:
                hero.command(friend, "move", {'x':19, 'y':40})
def friendMove():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            hero.command(friend, "move", {'x':44, 'y':38})

def attack():
    enemy = hero.findNearestEnemy()
    hero.move({'x':56, 'y':51})
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        if hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        else:
            hero.attack(enemy)

def collect():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)

while True:
    friends = hero.findFriends()
    item = hero.findNearestItem()
    enemy = hero.findNearestEnemy()
    pet.on("spawn", onSpawn)
    pet.moveXY(60, 56)
    summon()
    command()
    friendMove()
    move()
    if enemy:
        attack()
    if hero.time < 40:
        collect()
    

I fixed the problem of collecting, but I still can’t move to the summoning stone.
Lydia

Hello?
Lydia
2020 2020

Code using Naria
def onSpawn():
    if pet.isReady("shape-shift"):
        pet.shapeShift() 

def summon():
    if hero.gold > hero.costOf("archer"):
        hero.summon("archer")

def command():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            enemyF = friend.findNearestEnemy()
            if enemyF:
                hero.command(friend, "attack", enemyF)
            else:
                hero.command(friend, "move", {'x':19, 'y':40})
def friendMove():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            hero.command(friend, "move", {'x':44, 'y':38})

def attack():
    enemy = hero.findNearestEnemy()
    hero.move({'x':56, 'y':51})
    if enemy:
        if hero.isReady("throw"):
            hero.throw(enemy)
        if hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        else:
            hero.attack(enemy)

def collect():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)

def move():
    hero.move({'x':19, 'y':40})
    hero.move({'x':56, 'y':51})
    
while True:
    friends = hero.findFriends()
    item = hero.findNearestItem()
    enemy = hero.findNearestEnemy()
    pet.on("spawn", onSpawn)
    pet.moveXY(60, 56)
    summon()
    command()
    friendMove()
    move()
    if enemy:
        attack()
    if hero.time < 40:
        collect()

Naria'a Equipment

Code using Tharin
def summon():
    if hero.gold > hero.costOf("archer"):
        hero.summon("archer")

def command():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            enemyF = friend.findNearestEnemy()
            if enemyF:
                hero.command(friend, "attack", enemyF)
            else:
                hero.command(friend, "move", {'x':19, 'y':40})
def friendMove():
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "archer":
            hero.command(friend, "move", {'x':44, 'y':38})

def attack():
    enemy = hero.findNearestEnemy()
    hero.move({'x':56, 'y':51})
    if enemy:
        if hero.isReady("bash"):
            hero.bash(enemy)
        if hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        else:
            hero.attack(enemy)

def collect():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)

while True:
    friends = hero.findFriends()
    item = hero.findNearestItem()
    enemy = hero.findNearestEnemy()
    pet.on("spawn", onSpawn)
    pet.moveXY(60, 56)
    summon()
    command()
    friendMove()
    move()
    if enemy:
        attack()
    if hero.time < 40:
        collect()
    
Tharin's Equipment

image

Both codes still makes my hero go brrrrrrrrr.

Lydia

I think just need add codes before your while True/gold collecting code and kill yeti code