# Beating The Invisible

**URL:** https://discourse.codecombat.com/t/beating-the-invisible/9998
**Category:** Uncategorized
**Created:** [December 17, 2016, 11:58am UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998 "2016-12-17T11:58:47Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![General\_Irons](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@General\_Irons](https://discourse.codecombat.com/u/General_Irons)
#### Post date: [December 17, 2016, 11:58am UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998/1 "2016-12-17T11:58:47Z")

</div>

This code is used in Multiplayer Treasure Grove, I use a goliath, and my enemy can use invisibility. My problem is that I cannot use my special attacks as goliath with my code, but I can still use my base attacks and collect coins when the enemy is invisible. However, if I edit my code so that I can use my special attacks, my character eventually walks in one direction and doesn’t attack the enemy or collect coins. May I have any tips to avoid being “Invisibled” (aka walks in one direction and doing nothing) and also use my special attacks?  
This is my code at the bottom.

This one can still use base attacks and collect coins when the enemy is invisible, but cannot use any special attacks.

```python
totalGold = 0
def main():
    enemy = hero.findNearestEnemy()
    if enemy and hero.distanceTo(enemy) < 15:
        fight()
        return
    else:
        findItem()
        return
def fight():
    enemy = hero.findNearestEnemy()
    if hero.canCast("invisibility", hero):
        hero.cast("invisibility", hero)
    if enemy.health < 200:
        hero.attack(enemy)
    else:
        if enemy:
            if enemy:
                hero.attack(enemy)
            elif hero.isReady("stomp"):
                hero.stomp()
            elif hero.isReady("throw"):
                hero.throw(enemy)
            elif hero.canCast("chain-lightning", enemy):
                hero.cast("chain-lightning", enemy)
            elif hero.isReady("hurl"):
                hero.hurl(enemy)
            else:
                hero.move(enemy.pos)
        return

def findItem():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
        totalGold += item.value
    else:
        return
while True:
    if hero.gold >= 100:
        hero.say("2 EZ")
    else:
        main()

```

This one can use my special attacks, but my character eventually walks in one direction and doesn’t attack the enemy or collect coins.

```python
totalGold = 0
def main():
    enemy = hero.findNearestEnemy()
    if enemy and hero.distanceTo(enemy) < 15:
        fight()
        return
    else:
        findItem()
        return
def fight():
    enemy = hero.findNearestEnemy()
    if hero.canCast("invisibility", hero):
        hero.cast("invisibility", hero)
    if enemy.health < 200:
        hero.attack(enemy)
    else:
        if enemy:
            if enemy:
                hero.attack(enemy)
            if hero.isReady("stomp"):
                hero.stomp()
            elif hero.isReady("throw"):
                hero.throw(enemy)
            elif hero.canCast("chain-lightning", enemy):
                hero.cast("chain-lightning", enemy)
            elif hero.isReady("hurl"):
                hero.hurl(enemy)
            else:
                return
        return

def findItem():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
        totalGold += item.value
    else:
        return
while True:
    if hero.gold >= 100:
        hero.say("2 EZ")
    else:
        main()

```

Also shoutout to Chronist Gilverbrind, my opponent. GG WP

---

<div class="post-metadata">

### Author: ![htrnblr](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@htrnblr](https://discourse.codecombat.com/u/htrnblr)
#### Post date: [December 17, 2016, 12:34pm UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998/2 "2016-12-17T12:34:31Z")

</div>

try to add  
check for invi status

```python
enemy.hasEffect( "hide" ) 

```

---

<div class="post-metadata">

### Author: ![General\_Irons](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@General\_Irons](https://discourse.codecombat.com/u/General_Irons)
#### Post date: [December 17, 2016, 12:47pm UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998/3 "2016-12-17T12:47:56Z")

</div>

Enemy hides during an attack function, so attack function cannot attack null, so the hero is confused. The checking function doesn’t ID the “hide” because the “hide” always happens when my hero is using the attack function. Thanks though

---

<div class="post-metadata">

### Author: ![General\_Irons](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@General\_Irons](https://discourse.codecombat.com/u/General_Irons)
#### Post date: [December 17, 2016, 12:50pm UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998/4 "2016-12-17T12:50:32Z")

</div>

Also forgot to mention, the hero gets stuck on the attack function when it is “Invisibled”, so it cannot move onto another funtion.

---

<div class="post-metadata">

### Author: ![htrnblr](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@htrnblr](https://discourse.codecombat.com/u/htrnblr)
#### Post date: [December 17, 2016, 2:12pm UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998/5 "2016-12-17T14:12:29Z")

</div>

interesting he execute invi after you select him as target  
invi cast time is 0.5  
so my strategy move near  
for example attack take 0.25  
you can execute 2 attack  
while he casting

working good enough

```python
totalGold = 0
def main():
    enemy = hero.findNearestEnemy()
    if enemy and hero.distanceTo(enemy) < 15:
        fight()
        return
    else:
        findItem()
        return
def fight():
    enemy = hero.findNearestEnemy()
    if hero.canCast("invisibility", hero):
        hero.cast("invisibility", hero)
    if enemy.health < 200:
        hero.attack(enemy)
    else:
        if enemy:
            if ( enemy
                and not enemy.hasEffect( "hide" ) ):
                    while ( hero.distanceTo( enemy ) > 5 ):
                        hero.move( enemy.pos )
                    hero.attack( enemy )
                    hero.attack( enemy )
            if ( hero.isReady("stomp")
                and not enemy.hasEffect( "hide" ) ):
                    hero.stomp()
            elif ( hero.isReady("throw")
                and not enemy.hasEffect( "hide" ) ):
                    hero.throw(enemy)
            elif ( hero.canCast("chain-lightning", enemy)
                and not enemy.hasEffect( "hide" ) ):
                    hero.cast("chain-lightning", enemy)
            elif ( hero.isReady("hurl")
                and not enemy.hasEffect( "hide" ) ):
                    hero.hurl(enemy)
            else:
                return
        return

def findItem():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
        totalGold += item.value
    else:
        return
while True:
    if hero.gold >= 100:
        hero.say("2 EZ")
    else:
        main()

```

---

<div class="post-metadata">

### Author: ![General\_Irons](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@General\_Irons](https://discourse.codecombat.com/u/General_Irons)
#### Post date: [December 17, 2016, 2:58pm UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998/6 "2016-12-17T14:58:42Z")

</div>

Tnkas for helping me with the “Invisibled” Problem. However, I see that I am only able to use one of my specials. Is there a reason why that is happening?  
PS, I see you on dueling grounds global, GG

---

<div class="post-metadata">

### Author: ![General\_Irons](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@General\_Irons](https://discourse.codecombat.com/u/General_Irons)
#### Post date: [December 17, 2016, 3:13pm UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998/7 "2016-12-17T15:13:16Z")

</div>

O yeah, How does he do that? Those are some skills

---

<div class="post-metadata">

### Author: ![htrnblr](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@htrnblr](https://discourse.codecombat.com/u/htrnblr)
#### Post date: [December 17, 2016, 4:17pm UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998/8 "2016-12-17T16:17:11Z")

</div>

nothing special

```python
if ( enemy.target == hero ):
    hero.cast( "invisibility" )

```

i think

about skill  
looks like something like this :  
2 cases  
1 you attack him he execute invi – end of story  
2 you attack him then stomp  
cos all other skills at elif  
we go to the another cycle  
at this moment he out of 15 m – end of story

before execution of skill  
you must be sure  
you at skill execution range  
it will execute faster than he execute invi

---

<div class="post-metadata">

### Author: ![General\_Irons](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@General\_Irons](https://discourse.codecombat.com/u/General_Irons)
#### Post date: [December 18, 2016, 10:07am UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998/9 "2016-12-18T10:07:45Z")

</div>

Thnx htrnblr. I was able to get around the problem, but I still lost. LOL, I’m Just too slow, even with the speed ring 😄  
This code works thou, thanks M8

```python
totalGold = 0
def main():
    enemy = hero.findNearestEnemy()
    if enemy and hero.distanceTo(enemy) < 15:
        fight()
        return
    else:
        findItem()
        return
def fight():
    enemy = hero.findNearestEnemy()
    if hero.canCast("invisibility", hero):
        hero.cast("invisibility", hero)
    if enemy.health < 200:
        hero.attack(enemy)
    else:
        if enemy:
            if (enemy
                and not enemy.hasEffect( "hide" ) ):
                    while ( hero.distanceTo( enemy ) > 5 ):
                        hero.move( enemy.pos )
                    hero.attack( enemy )
            if (hero.isReady("stomp")
                and not enemy.hasEffect( "hide" ) ):
                    while ( hero.distanceTo( enemy ) > 20 ):
                        hero.move( enemy.pos )
                    hero.stomp()
            if (hero.isReady("throw")
                and not enemy.hasEffect( "hide" ) ):
                    hero.throw(enemy)
            if (hero.canCast("chain-lightning", enemy)
                and not enemy.hasEffect( "hide" ) ):
                    hero.cast("chain-lightning", enemy)
            if (hero.isReady("hurl")
                and not enemy.hasEffect( "hide" ) ):
                    hero.hurl(enemy)
            else:
                return
        return

def findItem():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
        totalGold += item.value
    else:
        return
while True:
    if hero.gold >= 100:
        hero.say("2 EZ")
    else:
        main()

```

---

<div class="post-metadata">

### Author: ![htrnblr](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@htrnblr](https://discourse.codecombat.com/u/htrnblr)
#### Post date: [December 18, 2016, 11:58am UTC](https://discourse.codecombat.com/t/beating-the-invisible/9998/10 "2016-12-18T11:58:35Z")

</div>

i have managed to win  
but I had to completely change tactics  
to the hammer - fences - targeted hurl
