Village Warder - Python

I am having an issue with this block of code, specifically with the game loop patrolling. My avatar will move to (60, 31) and it will register that the enemy has been seen but it will not execute an attack on the enemy using the variable findAndAttackEnemy() considering cleave is not ready yet.

Thanks!

# This function attacks the nearest enemy.
def findAndAttackEnemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)

# Define a function to cleave enemies (but only when the ability is ready).
def findAndCleaveEnemy():
    # Find the nearest enemy:
    enemy = hero.findNearestEnemy()
    # If an enemy exists:
    if enemy:
        # And if "cleave" is ready:
        hero.isReady("cleave")
        # It's time to cleave!
        hero.cleave(enemy)
    pass

# In your main loop, patrol, cleave, and attack.
while True:
    # Move to the patrol point, cleave, and attack.
    hero.moveXY(35, 34)
    findAndCleaveEnemy()
    findAndAttackEnemy()
    hero.moveXY(60, 31)
    findAndCleaveEnemy()
    findAndAttackEnemy()
    pass
1 Like

You should be using an if statement here to check if cleave is ready.

2 Likes

a la place de :

if enemy: hero.isReady("cleave") hero.cleave(enemy)

tu pourrai peux etre mettre:

while enemy.health < 0 and hero.isReady(cleave):
    hero.cleave(enemy)

So it needed to be nested. Those can be confusing sometimes. Thanks!

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.