i am playing the level siege of stonehold. I have made up this code that makes my soldier follow the flag and attack enemies when nearby. Its working fine until i want to make me soldier cleave. i know the cleave command BUT i want to make it cleave when it is near the soldiers. While i was playing i would make my soldier walk toward the enemies but it would sometimes cleave along the way and not cleave when i wanted it to.
heres my code:
# You'll need great equipment and strategy to win. loop: enemy = self.findNearestEnemy() flag = self.findFlag("green") target = enemy if flag: flagpos = flag.pos fx = flag.pos.x fy = flag.pos.y self.pickUpFlag(flag) elif enemy: self.distanceTo(target) self.findNearestEnemy() self.attack(enemy) elif enemy: enemy = self.findNearestEnemy() distance = self.distanceTo(enemy.pos) if distance < 4: self.isReady("cleave") self.cleave(enemy)
I need help on this last code ^^^^^ i want to know what is the best way to make my soldier cleave when near an enemy. I tried putting that same code for cleave on the code above it that was for attacking but it didn’t work out well so i just made an individual code. Am i doing it right though? It says it is right but the soldier doesnt even cleave or maybe im not getting close enough? Im not sure…