Help with Air Bridge (Python)


#1

Hi there, I’m using this code, but the pet cannot carry it, it says, I can’t carry it… is it because the Hero has already killed it? Should I find a way for the weakest to not be killed?

Here’s my code

# Help peasants to escape.



def onSpawn(event):
    # We need to save three peasants.
    remainingPeasants = 3
    while remainingPeasants > 0:
        # Take a good position.
        pet.moveXY(40, 55)
        peasant = pet.findNearestByType("peasant")
        if peasant:
            # Carry the peasant to the center passage.
            pet.carryUnit(peasant, 40, 34)
            remainingPeasants -= 1
    # Next find a weak ogre and carry it to the fire traps:
    #define globals
    enemies = hero.findEnemies()
    enemyCount = 0
    minHealth = 9999
    weakEnemy = None
    #find weakest enemy
    while enemyCount < len(enemies):
        
        enemy = enemies[enemyCount]
        enemyHealth = enemy.health
        if enemyHealth < minHealth:
            minHealth = enemyHealth
            weakEnemy = enemy
            
        enemyCount += 1
        
        
    #carry the weakest enemy
    pet.moveXY(weakEnemy.pos.x, weakEnemy.pos.y)
    pet.carryUnit(weakEnemy, 41, 17)

pet.on("spawn", onSpawn)

# Fight!
while True:
    #find enemy
    enemy = hero.findNearestEnemy()
    #if enemy, attack
    if enemy:
        hero.attack(enemy)
    

THANKS!


#2

try adding in a munchkin = pet.findNearestByType(“munchkin”) in your code
and take out the while loop


#3

your if statement is wrong
set minhealth to 0
and then if enemyhealth > minhealth


#4

ur hero is probably killing the munchkin too fast, and the next enemy which is the weakest is probably an injured ogre since you only specify enemy.health and not enemy.maxHealth

Change enemy.health for enemy.maxHealth and you could also specify the enemy type for “munchkin”

Good luck


#5

You’re right!! thanks


#6

Thanks you’re right!!

An if enemy is not weakEnemy did the trick