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

Air Bridge In Sarven Desert using the Python Coding Language

I need help on Air Bridge in the desert. I get the Fight code right, but it doesn’t drop the munchkin.
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
munchkin = pet.findNearestByType(“munchkin”)
# Carry a munchkin to the fire traps:
pet.carryUnit(munchkin, 40, 17)

pet.on(“spawn”, onSpawn)

Fight!

while True:
enemy = hero.findNearestEnemy()
if enemy:
while enemy.health >= 0:
hero.attack(enemy)

Sorry i have to re frormat it. Here

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
    munchkin = pet.findNearestByType("munchkin")
    # Carry a munchkin to the fire traps:
    pet.carryUnit(munchkin, 40, 17)

pet.on("spawn", onSpawn)

# Fight!
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        while enemy.health >= 0:
            hero.attack(enemy)

“it doesn’t drop the munchkin”? - I pass the level with your code


I suppose you get a similar picture?
Try submitting several times and if you fail you can get a victim by id if your hero kills the munchkin…
Or use a knight if you fight with a subscriber hero…

how would i get a victim by id? You have to drop the munchkin on the firebombs.

Do if enemy.id=='[Name]'

Nope. it doesnt work

Chaboi, have you saved the two soldiers? I passed the level long time ago and then I succeeded to save only one of them. I must do it …
@mr_javascript post a picture of the grffin last action.

it puts the third peasant in the behind the hero. then it goes to the hero fighting monsters and just hovers there. It may be because the hero is killing all the munchkins before the griffin can get them.

No the griffin has an expression for the thangs it can carry. It’s something like hero.maxHealth/5 or something. So in conclusion the griffin can’t carry the hero.

So choose one of the munchkins from the lower left corner
if enemy.id==‘Dobo’
or
if enemy.id==‘Palt’

You can perhaps somehow launch yourself with firetraps across the river. :man_shrugging:

I thought that I’m the only one knowing this trick… Just kidding :slight_smile:

1 Like

Maybe use a hero with little mass, like Ritic, and do it. Two firetraps will launch you quite far…

The knights are also good aviators - I’ve made some experiments with them… :slight_smile:

2 Likes

it is
pet.carryUnit()

I noticed that Ritic (or any ranger) might shoot the munchkin that the baby griffin is carrying with findNearestEnemy() which prevents the fire-traps from detonating. I had to add an extra check to make sure that he attacks the enemies that are above him.

fire%20traps%20not%20detonating

2 Likes

Brooksy, have you menage to solve your problem and how?
For me the most easy solution is to move the hero toward the top - (40, 55)? But if it doesn’t help you can command your hero ( or your pet if you don’t have the most advanced glasses) to chose the enemy by type or name: In the code below I use javascript filter, but you can write the same functionality yourself:

function isVictim(enemy){
//   return enemy.type == 'ogre'; // Variant A - working
  return enemy.id == 'Merna';     // Variant B - working
}
    var foes = pet.findEnemies(), // hero.findEnemies() will fail if 
                                  // you don't have twilight glasses
        // victims = foes.filter(isVictim); // Variant A - working
        victim = foes.filter(isVictim)[0];
// and then into onSpawn function
    // pet.carryUnit(pet.findNearest(victims), 40, 19); // Variant A - working
     pet.carryUnit(victim, 40, 19);                     // Variant B - working

This is a comparison between the method given in the help and in the thang editor:lpet pet
In reality you need too little to pass this level with a simple hero, no books, no boots, no glasses:


And thank you for the question - didn’t know the baby griffin has unlimited vision :slight_smile:

1 Like

I simply added an extra check to make sure the enemy.pos.y is greater than the heroes Y. It took me a while to figure out why the dropped munchkin wasn’t setting of the mines. Once I figured out the munchkin needs to be alive when being dropped, it was a quick fix.

Yeah, my gear is overkill for all of these levels. I feel like I’ve been making more work for myself by using better heroes with better gear going through the second time. I end up writing extra code to compensate for the extra variables that weren’t intended for the level. I don’t remember these type of issues when I went through this the first time with a warrior hero. Either way, it is good practice.

1 Like

Yes, this is the quickest way to avoid shooting the griffin victim. And I succeeded to pass the level without casualties. Ida rescued all her peasants and soldiers even without fighting using some of the hints above - see the video to know how: air bridge
/ no code - no complete solution/