That all looks good.
Does lightning just require a target, or does it require an X and Y position?
(hero.cast('lightning', strongest), or hero.cast('lightning',strongest.pos.x,strongest.pos.y))
The only problem with this code is that it always lightnings the strongest enemy which is almost always the hero and the hero is resistant against any spells.
So my code isnât working the way I want it to. I made a code that is supposed to lightning all enemys with health greater than 310 but even though I put it in my base code it just dosenât work. Help?
def lightning():
def findStrongestEnemy(enemies):
strongest = None
strongestHealth = 0
enemyIndex = 0
# While enemyIndex is less than the length of enemies:
while enemyIndex < len(enemies):
# Set an enemy variable to enemies[enemyIndex]
en = enemies[enemyIndex]
# If enemy.health is greater than strongestHealth
if en.health > strongestHealth:
# Set `strongest` to enemy
strongest = en
# Set strongestHealth to enemy.health
strongestHealth = en.health
# Increment enemyIndex
enemyIndex += 1
return strongest
enemies = hero.findEnemies()
strongest = findStrongestEnemy(enemies)
if strongest.health >= 310:
hero.cast("lightning", strongest.pos, strongest.pos)
It should be hero.cast("lightning", strongest.x, strongest.y), but Iâm not sure that will work 100% of the time either. I had trouble with the lightning targeting skeletons even though:
They arenât the strongest enemy.
They arenât the nearest enemy.
The position I inputted was nowhere near them.
So idk whatâs up with lightning. I still have code that targets shamans and that seems to work just fine, but when I try to target either catapults or brawlers it hits a skeleton instead.