# Ranger forgot how to use his gun

**URL:** <https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199>\
**Category:** Uncategorized\
**Created:** [October 10, 2015, 10:34am UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199 "2015-10-10T10:34:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![PixelAA](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@PixelAA](https://discourse.codecombat.com/u/PixelAA)\
**Post date:** [October 10, 2015, 10:34am UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/1 "2015-10-10T10:34:01Z")

</div>

When playing in the forest level “Tactical Timing”, my ranger is unable to use his gun. I have tried switching out my bought weapon with the freebie crossbow he came with, but no change. I also added the attack range thinking that could be the problem. I have him say a message to see if he’s firing and my eyes have just missed it, but he never says “bam!”.

Is this a game bug, or just something I’m missing in my code?

```python
// Help out on the front line.
// Move back to a flag if any try to sneak by.
loop{
    var enemy = this.findNearest(this.findEnemies());    
    var flag = this.findFlag();
    if(flag){
        this.pickUpFlag(flag);
    }
    if(enemy){
        if(this.isReady("throw") && this.distanceTo(enemy) < this.throwRange){
            this.throw(enemy);
        }else if(this.canCast("chain-lightning", enemy)){
            this.cast("chain-lightning", enemy);
        }else if(this.canElectrocute(enemy)){
            this.electrocute(enemy);
        }else if(this.distanceTo(enemy) < this.attackRange){
            this.attack(enemy);
            this.say("bam!");
        }else{
            this.heal(this);
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [October 10, 2015, 2:18pm UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/2 "2015-10-10T14:18:45Z")

</div>

Heal has a cooldown. You’re telling yourself to heal when there’s no attackers in range. However, if you use `heal` before it is ready, then your hero is stuck trying to cast `heal` until it is ready. Add a `if (this.canCast("heal")) {`.

---

<div class="post-metadata">

**Author:** ![PixelAA](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@PixelAA](https://discourse.codecombat.com/u/PixelAA)\
**Post date:** [October 10, 2015, 3:46pm UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/3 "2015-10-10T15:46:50Z")

</div>

Hmm, removing heal entirely didn’t make the problem go away.

```python
...
if(enemy){
        if(this.isReady("throw") && this.distanceTo(enemy) < this.throwRange){
            this.throw(enemy);
        }else if(this.canCast("chain-lightning", enemy)){
            this.cast("chain-lightning", enemy);
        }else if(this.canElectrocute(enemy)){
            this.electrocute(enemy);
        }else{
            this.attack(enemy);
            this.say("bam!");
        }
    }

```

---

<div class="post-metadata">

**Author:** ![PixelAA](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@PixelAA](https://discourse.codecombat.com/u/PixelAA)\
**Post date:** [October 10, 2015, 3:50pm UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/4 "2015-10-10T15:50:19Z")

</div>

To pass this level (in other words to kill all ogres before time ran out), I had to delete all of my special attacks.

```python
loop{
    var enemy = this.findNearest(this.findEnemies());    
    var flag = this.findFlag();
    if(flag){
        this.pickUpFlag(flag);
    }
    if(enemy){
        this.attack(enemy);
    }
}

```

Which is kinda 😢 really.

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [October 10, 2015, 8:19pm UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/5 "2015-10-10T20:19:51Z")

</div>

Huh. I doubt this intentional. Well, when in doubt, call @nick.

---

<div class="post-metadata">

**Author:** ![trotod](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/trotod/32/3263_2.png) [@trotod](https://discourse.codecombat.com/u/trotod)\
**Post date:** [October 10, 2015, 10:24pm UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/6 "2015-10-10T22:24:59Z")

</div>

`this.electrocute()` also has an `isReady` check, so you’ll also have to add that before you attempt to electrocute someone.

````javascript
if (this.isReady('electrocute') && this.canElectrocute(enemy)) {
    this.electrocute(enemy)
} else {
    this.attack(enemy)
}
```
````

---

<div class="post-metadata">

**Author:** ![PixelAA](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@PixelAA](https://discourse.codecombat.com/u/PixelAA)\
**Post date:** [October 11, 2015, 6:59am UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/7 "2015-10-11T06:59:53Z")

</div>

Ah that’s what it was. Who would’ve thought electrocuting somebody would be so complicated.

Thanks trotod and ChronistGilver for looking through my code!

---

<div class="post-metadata">

**Author:** ![Msakr](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Msakr](https://discourse.codecombat.com/u/Msakr)\
**Post date:** [October 12, 2015, 7:43am UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/8 "2015-10-12T07:43:57Z")

</div>

Also, self.say() can burn a lot of time. Whenever you say, your character stops for a long moment.

Also, you might want to clean up your special attack tests.

1. Electrocute only slows down the run speed of your target from the descriptions I have seen. So, if the target is already attacking you and you are not planning to run, why are you using it? Also, I think the canElectrocute already incorporates the cool down, but I could be wrong on that.
2. Chain-lightning has a long cool down and can jump between targets up to 8 times, doing less damage each time. You may want to consider checking to make sure there is another enemy within 20 feet of your first target. In Python, I might suggest:  
TarB = enemy.findNearest(enemy.findEnemies())  
if TarB:  
…DistanceToTarB = enemy.DistanceTo(TarB)  
…if DistanceToTarB \< 20:  
…self.cast(“chain-lightning”, enemy)

That way, there are at least 2 targets. Depending on level, you might want to check the .health of the first target is greater than 99 as well.

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [October 12, 2015, 9:43pm UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/9 "2015-10-12T21:43:35Z")

</div>

`canElectrocute` should incorporate the cooldown, but I guess it doesn’t. Anyone up for submitting a patch?

---

<div class="post-metadata">

**Author:** ![Msakr](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Msakr](https://discourse.codecombat.com/u/Msakr)\
**Post date:** [October 13, 2015, 3:16am UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/10 "2015-10-13T03:16:36Z")

</div>

Actually, I think canElectrocute actually does incorporate the cooldown currently or it is a really short cool down as I have not noticed a significant pause while waiting for it to fire. If it doesn’t, wish I knew enough to be able to develop and submit a patch…

If we were programming in Basic (the original mind you), Pascal, LISP or Visual Basic for Applications (many, many years ago), I might have the nerve to propose such a patch. To be honest, I originally came here looking for ways to teach my youngest how to code and got into solving the problems. If you’re looking for a true coder, I’m a far better attorney these days. 😉

---

<div class="post-metadata">

**Author:** ![PixelAA](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@PixelAA](https://discourse.codecombat.com/u/PixelAA)\
**Post date:** [October 15, 2015, 8:54am UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/11 "2015-10-15T08:54:34Z")

</div>

Some interesting strategies to try our Msakr. Thanks for the tips!

Did I understand correctly that the electrocute ring and the gloves share the same cool-down?

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [October 15, 2015, 2:26pm UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/12 "2015-10-15T14:26:19Z")

</div>

That is incorrect. The Steel Ring’s `electrocute` ability has a cooldown of eight seconds, while the Emperor’s Gloves’ `chain-lightning` has a cooldown of twenty seconds.

---

<div class="post-metadata">

**Author:** ![anon71151045](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@anon71151045](https://discourse.codecombat.com/u/anon71151045)\
**Post date:** [September 30, 2016, 9:19pm UTC](https://discourse.codecombat.com/t/ranger-forgot-how-to-use-his-gun/5199/13 "2016-09-30T21:19:28Z")

</div>

Just maybe use another hero like Tharin.
