# Don't know how to make tharin attack certain things in Dungeon Arena

**URL:** <https://discourse.codecombat.com/t/dont-know-how-to-make-tharin-attack-certain-things-in-dungeon-arena/1195>\
**Category:** Uncategorized\
**Created:** [October 16, 2014, 8:00pm UTC](https://discourse.codecombat.com/t/dont-know-how-to-make-tharin-attack-certain-things-in-dungeon-arena/1195 "2014-10-16T20:00:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominion](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dominion/32/1571_2.png) [@Dominion](https://discourse.codecombat.com/u/Dominion)\
**Post date:** [October 16, 2014, 8:00pm UTC](https://discourse.codecombat.com/t/dont-know-how-to-make-tharin-attack-certain-things-in-dungeon-arena/1195/1 "2014-10-16T20:00:57Z")

</div>

Code:

```javascript
this.findTypeInRange = function(units, type) {
    for (var i = 0; i < units.length; ++i) {
        var unit = units[i];
        if (unit.type === type && this.distance(unit) < this.attackRange)
            return unit;
    }
    return null;
};
var enemies = this.getEnemies();
for(var i = 0; i < enemies.length; ++i) {
  var enemy = enemies[i];
}
var shaman = this.findTypeInRange(enemies, "shaman");
var brawler = this.findTypeInRange(enemies, "brawler");
var thrower = this.findTypeInRange(enemies, "thrower", "spear");
var munchkin = this.findTypeInRange(enemies, "munchkin");

```

the this.findTypeInRange was something i saw in another post so i put it in but now i dont know how to make it work and the this.getNearestEnemy code is like bugged or something because when i do it tharin will target a unit but then when he gets close he’ll target another until he gets near the cave and stops and actaully hits something but by that point he is half dead already, and is swarmed i dont know why this happens but anyway i would like to figure ourt how to make him and other units target certain things and if not possible in dungeon arena i would like to start doing skyspan for more commands

Thanks in advance  
Dominion

---

<div class="post-metadata">

**Author:** ![Dominion](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dominion/32/1571_2.png) [@Dominion](https://discourse.codecombat.com/u/Dominion)\
**Post date:** [October 16, 2014, 8:03pm UTC](https://discourse.codecombat.com/t/dont-know-how-to-make-tharin-attack-certain-things-in-dungeon-arena/1195/2 "2014-10-16T20:03:10Z")

</div>

i think the this.findTypeInRange is to check if there is a troop in range and attack it maybe

---

<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 16, 2014, 8:35pm UTC](https://discourse.codecombat.com/t/dont-know-how-to-make-tharin-attack-certain-things-in-dungeon-arena/1195/3 "2014-10-16T20:35:23Z")

</div>

So far you aren’t telling Tharin to attack anything; is there more code that he’s using? Once you find if there is a shaman or brawler or thrower or munchkin, you might have to attack it if it exists. The `findTypeInRange` function that you have tried doesn’t find the nearest unit, though, so it may be finding ones that are further away and going to chase them.

Tharin’s attackRange is very short, though, so this probably won’t find any enemies to attack. You might want to change `this.attackRange` to `10` to make him chase something that’s pretty close.

---

<div class="post-metadata">

**Author:** ![Dominion](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dominion/32/1571_2.png) [@Dominion](https://discourse.codecombat.com/u/Dominion)\
**Post date:** [October 17, 2014, 7:41pm UTC](https://discourse.codecombat.com/t/dont-know-how-to-make-tharin-attack-certain-things-in-dungeon-arena/1195/4 "2014-10-17T19:41:06Z")

</div>

Ok thanks so much for telling me about the this.findTypeInRange that will help so much and the reason i dont have an attack code is because, now i know this, the this.findTypeInRange code was messing it up

---

<div class="post-metadata">

**Author:** ![Dominion](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dominion/32/1571_2.png) [@Dominion](https://discourse.codecombat.com/u/Dominion)\
**Post date:** [October 17, 2014, 7:51pm UTC](https://discourse.codecombat.com/t/dont-know-how-to-make-tharin-attack-certain-things-in-dungeon-arena/1195/5 "2014-10-17T19:51:30Z")

</div>

btw i think ill be using sky span because it has more commands which unlocks more options  
i would like to know if there is a way to cancel a code until a certain amount of time because i want to build a lot of units before the hero so i dont waste all my gold in the beggining

---

<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 17, 2014, 10:02pm UTC](https://discourse.codecombat.com/t/dont-know-how-to-make-tharin-attack-certain-things-in-dungeon-arena/1195/6 "2014-10-17T22:02:29Z")

</div>

Try something like this:

```javascript
if (this.now() > 10) {
    // Do this stuff only after the world has been running for 10 seconds.
    // ...
}

```
