The Storm Siege Topic

it just skips this code-
strongest = None
leastHealth = 0
enemyIndex = 0

while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]
    
    if enemies[enemyIndex].health > mostHealth:
        
        strongest = enemy 
        mostHealth = enemy.health
    
    enemyIndex += 1
if strongest:
    hero.cast('lightning','strongest.pos.x,strongest.pos.y')

so, what’s the points ranked on? (Just want to know since I am like 10-20 and I can beat 2 players above my score.

Firstly enemies isn’t defined at the start. Do you have it defined somewhere else in your Storm Siege code?

Remove the quotes from strongest.pos.x and strongest.pos.y, they’re not strings

And at the start, you’ve not changed leastHealth to mostHealth, so

won’t run

After that it should run alright.
(Please feel free to tell me if I’ve missed anything)

The points are ranked on your ratio of wins to losses in you simulations.

Why is there the unit.maxhealth sample code in the side bar if you can’t use it if you can please tell me how

1 Like

Try defining the unit first
As an example:

enemies = hero.findByType("soldier")
unit = enemies[0]
unitMaxHealth = unit.maxHealth
1 Like

Honestly soldiers and archers are BAD, (you should do like Warlocks or shamans),(ye I top 20), I have like 4 lines of code

1 Like

and I forgot to put this at the beginning - weakest = None

1 Like

so this good?(do I define enemies like this-
enemies =hero.findEnemies()
enemy = hero.findNearest(enemies)

strongest = None
mostHealth = 0
enemyIndex = 0
enemies = hero.findEnemies()
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]

    if enemies[enemyIndex].health > mostHealth:
        strongest = enemy 
    mostHealth = enemy.health
    enemyIndex += 1
if strongest:
    hero.cast('lightning',strongest.pos.x,strongest.pos.y)

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))

1 Like

nethier, both is wrong

1 Like

instead of
hero.cast(‘lightning’ , strongest.pos.x, strongest.pos.y)
try
hero.cast(‘lightning’ , strongest.x, strongest.y)

1 Like

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.

1 Like

You can overcome that issue by excluding the hero and towers from the possible enemies to cast lightning on.

strongest = None
mostHealth = 0
enemyIndex = 0
enemies = hero.findEnemies()
while enemyIndex < len(enemies):
    enemy = enemies[enemyIndex]

    if enemy.health > mostHealth and enemy.type != "tower" and enemy.x < 95 and enemy.x > 5:
        strongest = enemy 
        mostHealth = enemy.health
    enemyIndex += 1

if strongest:
    hero.cast('lightning',strongest.pos.x,strongest.pos.y)
1 Like

Hi all

so I just this over the weekend and what I really want to know is there a way to display output values?

1 Like

yall should fr be using soldiers guys cmon cant discriminate them like that they’re valuable (towards my strat at least)

1 Like

I use soldiers when enemies are attacking my base :stuck_out_tongue: meat shields

1 Like

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():
    enemies = hero.findEnemies()
    if enemies.health >= 310:
        hero.cast("lightning", enemies.pos, enemies.pos)
    
1 Like

Ok so I changed my code to this.

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)

and it STILL wont work.

1 Like

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:

  1. They aren’t the strongest enemy.
  2. They aren’t the nearest enemy.
  3. 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.

1 Like