Zero Sum: Collecting Coins

My enemy Pender is collecting coins so fast. He just summons so many griffin-riders so quickly.
PLS help me. I want to know how to collect coins fast too. Here is my code:

while (true) {
    if (hero.gold >= 50) {
        hero.summon("griffin-rider");
    }
    let friends = hero.findFriends();
    for (let friend of friends) {
        let item = hero.findNearestItem();
        let enemy = friend.findNearestEnemy();
        if (enemy && friend && friend.type == "griffin-rider") {
            hero.command(friend, "attack", enemy);
        }
        if(hero.isReady("fear")) {
            hero.cast("fear", enemy);
        }
        if (item) {
            hero.move(item.pos);
        }
    }
}

PLS help!

Use the spell “goldstorm” to summon a cloud that spawns 105 gold coins over the course of about 9 seconds. I would also recommend focusing gold coins first to stay on the trail of the gold cloud.

OK. I changed that, but she’s not trying to collect coins. She’s just trying to cast the “fear” spell.
I also tried taking it away but she won’t move.

By the way, I’m fighting you.

You need to move your code for the hero (fear and item code) out of the for loop, otherwise it will only activate if you have friends.

Yeah, also, if you’ve completed levels in Desert, you can write a BestItem function, with which you collect the best and nearest coins.

I did that. Pender is summoning two griffin-riders, but the second one doesn’t attack, and Pender isn’t collecting coins. I’ll show you my code one more time.

while (true) {
    if (hero.gold >= 50) {
        hero.summon("griffin-rider");
    }
    let friends = hero.findFriends();
    for (let friend of friends) {
        let item = hero.findNearestItem();
        let enemy = friend.findNearestEnemy();
        hero.cast("goldstorm");
        if (item && item.value >= 2) {
            hero.move(item.pos);
        }
        if (enemy && friend && friend.type == "griffin-rider") {
            hero.command(friend, "attack", enemy);
        }
    }
}
if (hero.isReady("fear")) {
    hero.cast("fear", enemy);
}

I wish I could record my code.

hero.cast("goldstorm");
You need to check if your hero is ready to cast goldstorm otherwise she will just sit there.

if (item && item.value >= 2) {
    hero.move(item.pos);
}

If your hero sees an item that isn’t greater than or equal to 2 value she will just not do anything. You need to create a new function to determine which items are better value for how far they are from your hero, like in some of the desert levels.

1 Like