# Sarven Treasure/ Python/ help/

**URL:** https://discourse.codecombat.com/t/sarven-treasure-python-help/27720
**Category:** Level Help
**Created:** [March 3, 2021, 2:56pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720 "2021-03-03T14:56:14Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)
#### Post date: [March 3, 2021, 2:56pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/1 "2021-03-03T14:56:14Z")

</div>

My character is doing everything right but just doesn’t have the time to collect 150 coins

```python
while True:
    enemy = hero.findNearestEnemy()
    items = hero.findItems()
    bestItem = None
    bestValue = 0
    itemsIndex = 0
    # Loop over the items array.
    # Find the item with the highest valueOverDistance()
    while itemsIndex < len(items):
        item = items[itemsIndex]
        if item.value / hero.distanceTo(item) > bestValue:
            bestItem = item
            bestValue = item.value / hero.distanceTo(item)
        itemsIndex += 1
    if enemy:
        if hero.isReady("cleave"):
            hero.cleave(enemy)
        elif hero.isReady("punch"):
            hero.punch(enemy)
        elif hero.isReady("bash"):
            hero.bash(enemy)
        else:
            hero.attack(enemy)
    if bestItem:
        hero.moveXY(bestItem.pos.x, bestItem.pos.y)
    else:
        pass

```

is there anyway i can speed them up?

---

<div class="post-metadata">

### Author: ![jka2706](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jka2706/32/13636_2.png) [@jka2706](https://discourse.codecombat.com/u/jka2706)
#### Post date: [March 3, 2021, 6:58pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/2 "2021-03-03T18:58:35Z")

</div>

Hi Some\_Guy,

Maybe only attack the enemy if it’s really close to you…?

Jenny

---

<div class="post-metadata">

### Author: ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)
#### Post date: [March 4, 2021, 3:59am UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/3 "2021-03-04T03:59:14Z")

</div>

try getting the emporers gloves, and use

```python
elif hero.canCast("chain-lightning", enemy)
    hero.cast("chain-lightning", enemy)

```

instead of

```python
elif hero.isReady("punch"):
    hero.punch(enemy)

```

also try using boots of jumping or leaping with this command OUTSIDE of if enemy as

1. they are faster
2. jumping to targets

```python
if hero.isReady("jump")
    hero.jumpTo(bestItem)

```

---

<div class="post-metadata">

### Author: ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)
#### Post date: [March 4, 2021, 2:44pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/4 "2021-03-04T14:44:06Z")

</div>

Hi great suggestion but my charracter has stopped finding the enemy

```python
enemy = hero.findNearestEnemy()
while True:
    items = hero.findItems()
    enemy = hero.findNearestEnemy()
    bestItem = None
    bestValue = 0
    itemsIndex = 0
    # Loop over the items array.
    # Find the item with the highest valueOverDistance()
    while itemsIndex < len(items):
        item = items[itemsIndex]
        if item.value / hero.distanceTo(item) > bestValue:
            bestItem = item
            bestValue = item.value / hero.distanceTo(item)
        itemsIndex += 1
    enemy = hero.findNearestEnemy()
    if bestItem:
        hero.jumpTo(bestItem)
    elif hero.distanceTo(enemy) <= 10:
        if hero.isReady("cleave"):
            hero.cleave(enemy)
        elif hero.isReady("punch"):
            hero.punch(enemy)
        elif hero.isReady("bash"):
            hero.bash(enemy)
        else:
            hero.attack(enemy)

```

Now they refuse to attack : (

---

<div class="post-metadata">

### Author: ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)
#### Post date: [March 4, 2021, 2:59pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/5 "2021-03-04T14:59:30Z")

</div>

I tried using Jump but they jump once and never they never Jump again nor move @Ashmit_Singh

```python
enemy = hero.findNearestEnemy()
while True:
    items = hero.findItems()
    enemy = hero.findNearestEnemy()
    bestItem = None
    bestValue = 0
    itemsIndex = 0
    # Loop over the items array.
    # Find the item with the highest valueOverDistance()
    while itemsIndex < len(items):
        item = items[itemsIndex]
        if item.value / hero.distanceTo(item) > bestValue:
            bestItem = item
            bestValue = item.value / hero.distanceTo(item)
        itemsIndex += 1
    enemy = hero.findNearestEnemy()
    if enemy:
        Distance = hero.distanceTo(enemy)
    if Distance <= 10:
        if hero.isReady("cleave"):
            hero.cleave(enemy)
        elif hero.isReady("punch"):
            hero.punch(enemy)
        elif hero.isReady("bash"):
            hero.bash(enemy)
        else:
            hero.attack(enemy)    
    elif bestItem:
        hero.jumpTo(bestItem)
        hero.moveXY(bestItem.pos.x, bestItem.pos.y)

```

---

<div class="post-metadata">

### Author: ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)
#### Post date: [March 4, 2021, 3:00pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/7 "2021-03-04T15:00:46Z")

</div>

I found what was wrong @jka2706 but they are still to slow

---

<div class="post-metadata">

### Author: ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)
#### Post date: [March 4, 2021, 3:12pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/8 "2021-03-04T15:12:29Z")

</div>

wait i fixed it but now my character is killing all the enemies then stopping

```python
while True:
    items = hero.findItems()
    enemy = hero.findNearestEnemy()
    bestItem = None
    bestValue = 0
    itemsIndex = 0
    # Loop over the items array.
    # Find the item with the highest valueOverDistance()
    while itemsIndex < len(items):
        item = items[itemsIndex]
        if item.value / hero.distanceTo(item) > bestValue:
            bestItem = item
            bestValue = item.value / hero.distanceTo(item)
        itemsIndex += 1
    
    if enemy:
        Distance = hero.distanceTo(enemy)
    
    if Distance <= 10:
        if hero.isReady("cleave"):
            hero.cleave(enemy)
        elif hero.isReady("punch"):
            hero.punch(enemy)
        elif hero.isReady("bash"):
            hero.bash(enemy)
        else:
            hero.attack(enemy)
    elif bestItem:
        if hero.isReady("jump"):
            hero.jumpTo(bestItem)
        else:
            hero.moveXY(bestItem.pos.x, bestItem.pos.y)

```

---

<div class="post-metadata">

### Author: ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)
#### Post date: [March 4, 2021, 3:21pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/9 "2021-03-04T15:21:48Z")

</div>

well… just tweak

```python
if Distance <= 10:

```

to

```python
if enemy and distance <= 10:

```

lowercase distance and note that you want to keeps both if enemy and the one i just said

---

<div class="post-metadata">

### Author: ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)
#### Post date: [March 4, 2021, 3:26pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/10 "2021-03-04T15:26:25Z")

</div>

Thank you that fixed the enemy issue but my character is still to slow

---

<div class="post-metadata">

### Author: ![avery\_witte](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/avery_witte/32/22046_2.png) [@avery\_witte](https://discourse.codecombat.com/u/avery_witte)
#### Post date: [March 4, 2021, 3:28pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/11 "2021-03-04T15:28:45Z")

</div>

save up for the ring of speed maybe do a couple of brawls to get it so your character can run fast unless you already have it

---

<div class="post-metadata">

### Author: ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)
#### Post date: [March 4, 2021, 3:30pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/12 "2021-03-04T15:30:06Z")

</div>

Ok ill get back to you if i get it

---

<div class="post-metadata">

### Author: ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)
#### Post date: [March 4, 2021, 3:33pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/13 "2021-03-04T15:33:40Z")

</div>

boots of leaping are cheaper i think, i use those, they are 4x faster than regular boots

---

<div class="post-metadata">

### Author: ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)
#### Post date: [March 4, 2021, 3:34pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/14 "2021-03-04T15:34:36Z")

</div>

I am using boots of leaping

---

<div class="post-metadata">

### Author: ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)
#### Post date: [March 4, 2021, 3:35pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/15 "2021-03-04T15:35:00Z")

</div>

huh… you are using a starter hero right?

---

<div class="post-metadata">

### Author: ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)
#### Post date: [March 4, 2021, 3:36pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/16 "2021-03-04T15:36:35Z")

</div>

if you are a sub, get the fastest one, otherwise, just go for the ring…

The precious ring saves you time so you don’t need to attack enemies, and so does the order of the paladin, but mainly speed ring

---

<div class="post-metadata">

### Author: ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)
#### Post date: [March 4, 2021, 3:38pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/17 "2021-03-04T15:38:05Z")

</div>

Yeah the red head  
I have

 ![Equipment Code combat 4.3.21.PNG](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/c/f/cf56c868a6156feba713efdc3a7526c3db021db7.jpeg)

---

<div class="post-metadata">

### Author: ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)
#### Post date: [March 4, 2021, 3:40pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/18 "2021-03-04T15:40:48Z")

</div>

huh i have this…

 ![Screen Shot 2021-03-04 at 9.09.49 PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/a/2/a292814685c1bf615422de97238233d1ef63b574.png)

have you tried using hero.jumpTo(target) yet?

---

<div class="post-metadata">

### Author: ![Some\_Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/some_guy/32/20317_2.png) [@Some\_Guy](https://discourse.codecombat.com/u/Some_Guy)
#### Post date: [March 4, 2021, 3:41pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/19 "2021-03-04T15:41:29Z")

</div>

Yeah but it was still to slow but helped me get closer

---

<div class="post-metadata">

### Author: ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)
#### Post date: [March 4, 2021, 3:43pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/20 "2021-03-04T15:43:49Z")

</div>

i dont know maybe alejandro or whatever is just slightly slower than the female starters or tharin, i didnt check the values… little difference

---

<div class="post-metadata">

### Author: ![Ashmit\_Singh](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Ashmit\_Singh](https://discourse.codecombat.com/u/Ashmit_Singh)
#### Post date: [March 4, 2021, 3:45pm UTC](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720/21 "2021-03-04T15:45:52Z")

</div>

OH WAIT…  
can you just like grind till mountain for boss star 2 or above and come back here pls…  
it will make your life so much easier

[Next page](https://discourse.codecombat.com/t/sarven-treasure-python-help/27720.md?page=2)
