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!