# \[solved\] Kelbintaph Crusaders targeting problem

**URL:** https://discourse.codecombat.com/t/solved-kelbintaph-crusaders-targeting-problem/20665
**Category:** Level Help
**Created:** [March 25, 2020, 7:19pm UTC](https://discourse.codecombat.com/t/solved-kelbintaph-crusaders-targeting-problem/20665 "2020-03-25T19:19:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Needs\_lots\_help](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/needs_lots_help/32/11675_2.png) [@Needs\_lots\_help](https://discourse.codecombat.com/u/Needs_lots_help)
#### Post date: [March 25, 2020, 7:19pm UTC](https://discourse.codecombat.com/t/solved-kelbintaph-crusaders-targeting-problem/20665/1 "2020-03-25T19:19:29Z")

</div>

```python
while True:
    friends = hero.findFriends()
    for friend in friends:
        witch = friend.findNearest(friend.findByType('witch'))
        ogre = friend.findNearest(friend.findByType('ogre'))
        if friend.id is "paladin":
            paladin = friend
        if friend.id is "archer":
            archer = friend
        if friend.id is "soldier":
            soldier = friend
        
        if witch:
            target = witch
        elif ogre:
            target = ogre
        else:
            target = friend.findNearestEnemy()
        if witch:
            hero.command(archer, "attack", witch)
        if paladin:
            hero.command(paladin, "defend", archer)
        if ogre:
            hero.command(soldier, "attack", ogre)

```

These are lines 20 to 43 of my code, and my archers only target the things near them. I’m trying to do different tactics for my units, but they keep targeting only the nearest. Why are they doing this?

---

<div class="post-metadata">

### Author: ![ducky](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ducky/32/9364_2.png) [@ducky](https://discourse.codecombat.com/u/ducky)
#### Post date: [March 25, 2020, 7:30pm UTC](https://discourse.codecombat.com/t/solved-kelbintaph-crusaders-targeting-problem/20665/2 "2020-03-25T19:30:41Z")

</div>

```python
witch = friend.findNearest(friend.findByType('witch')) 
ogre = friend.findNearest(friend.findByType('ogre'))
# it says NEAREST

```

Well, your troops are finding the ogres closest to them, as you stated.

---

<div class="post-metadata">

### Author: ![Needs\_lots\_help](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/needs_lots_help/32/11675_2.png) [@Needs\_lots\_help](https://discourse.codecombat.com/u/Needs_lots_help)
#### Post date: [March 25, 2020, 7:35pm UTC](https://discourse.codecombat.com/t/solved-kelbintaph-crusaders-targeting-problem/20665/3 "2020-03-25T19:35:29Z")

</div>

But I also tried to make them target the witch by making the witch a seperate enemy

```python
if witch:
            hero.command(archer, "attack", witch)

```

---

<div class="post-metadata">

### Author: ![ducky](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ducky/32/9364_2.png) [@ducky](https://discourse.codecombat.com/u/ducky)
#### Post date: [March 25, 2020, 7:36pm UTC](https://discourse.codecombat.com/t/solved-kelbintaph-crusaders-targeting-problem/20665/4 "2020-03-25T19:36:29Z")

</div>

Oh! I think I misunderstood the question.

---

<div class="post-metadata">

### Author: ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)
#### Post date: [March 25, 2020, 7:37pm UTC](https://discourse.codecombat.com/t/solved-kelbintaph-crusaders-targeting-problem/20665/5 "2020-03-25T19:37:12Z")

</div>

> [@Needs\_lots\_help](#):
>
> ```python
> if friend.id is "paladin": 
> paladin = friend 
> if friend.id is "archer": 
> archer = friend 
> if friend.id is "soldier": 
> soldier = friend
> 
> ```

I’m not sure whether this is the root of the problem, but friend.id is the friends name, e.g. Carol etc…  
You should use .type.  
Danny

---

<div class="post-metadata">

### Author: ![Needs\_lots\_help](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/needs_lots_help/32/11675_2.png) [@Needs\_lots\_help](https://discourse.codecombat.com/u/Needs_lots_help)
#### Post date: [March 25, 2020, 7:37pm UTC](https://discourse.codecombat.com/t/solved-kelbintaph-crusaders-targeting-problem/20665/6 "2020-03-25T19:37:52Z")

</div>

thanks ill take note of that

---

<div class="post-metadata">

### Author: ![Needs\_lots\_help](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/needs_lots_help/32/11675_2.png) [@Needs\_lots\_help](https://discourse.codecombat.com/u/Needs_lots_help)
#### Post date: [March 25, 2020, 7:41pm UTC](https://discourse.codecombat.com/t/solved-kelbintaph-crusaders-targeting-problem/20665/7 "2020-03-25T19:41:29Z")

</div>

i changed some stuff along with what you said. I don’t know it it’s a different problem now but they still target the nearest (I assume)

```python
while True:
    friends = hero.findFriends()
    for friend in friends:
        witch = friend.findNearest(friend.findByType('witch'))
        ogre = friend.findNearest(friend.findByType('ogre'))
        if friend.type is "paladin":
            paladin = friend
        if friend.type is "archer":
            archer = friend
        if friend.type is "soldier":
            soldier = friend
        
        if witch:
            target = witch
        elif ogre:
            target = ogre
        else:
            target = friend.findNearestEnemy()
        hero.command(soldier, "attack", target)
        hero.command(paladin, "defend", archer)
        hero.command(archer, "attack", target)

```

---

<div class="post-metadata">

### Author: ![Needs\_lots\_help](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/needs_lots_help/32/11675_2.png) [@Needs\_lots\_help](https://discourse.codecombat.com/u/Needs_lots_help)
#### Post date: [March 26, 2020, 5:57pm UTC](https://discourse.codecombat.com/t/solved-kelbintaph-crusaders-targeting-problem/20665/8 "2020-03-26T17:57:46Z")

</div>

as it turned out the code i left out was the reason why i wasn’t getting it done. I had my hero jump into the catapults, then shield a bunch, but it was outside the while true loop. I fixed it now.
