Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Help with how to tell If units are hostile in Sarven Desert

#1

I’m trying to refine my Harrowland algorithm, but I’m running into a problem. I have my units set to never attack units tagged as Sand Yaks, but sometimes the CPU attacks them, and my hero gets owned by it because he’ll never attack it. Is there a variable or something that will tell me if a unit is hostile to me, so that I can have my hero normally avoid the yaks, but still fight one if it becomes hostile?

#2

Hi @AyeAyeCaptain, welcome to the CodeCombat Discourse.
Could you post your code so I can see what’s going on?
Also could you post it formatted. To see what “formatted” means, see this topic.
Thanks,
:lion: :lion: :lion:

#3

Here’s the code:

var fight = function(target) {
    if (hero.canCast('chain-lightning')) {
        hero.cast("chain-lightning", target);
    }else if (hero.isReady('bash')) {
        hero.bash(target);
    }else{
        hero.attack(target);
    }
    hero.shield();
};
while(true) {
    var enemies = hero.findEnemies();
    var not_yaks = [];
    for (var i = 0; i < enemies.length; i++) {
        if (enemies[i].type !== 'sand-yak') {
            not_yaks.push(enemies[i]);
        }
    }
    var enemy = hero.findNearest(not_yaks);
    if (enemy) {
        fight(enemy);
    }
}

And here’s what gear I have (kinda OP, I know):
gear
If you run the code I already have in the level, I do technically beat the CPU, but I’d rather win by being smart than just tanking out the evil yak.

#4

I’ve run into this a lot in my time on Harrowland. You’re using Chain-lightning, if you watch carefully you’ll see your chain of lightning hit the yak. I recommend not using Emperor’s gloves at all because having a yak against you can be disastrous and it’s almost impossible to stop it hitting the yak because you can’t control the lightning.
:lion: :lion: :lion:

#5

Welcome to CodeCombat and our forum @AyeAyeCaptain! We hope you will be able to learn through the forum and to most importantly have fun! I’m @Luke10. My real name is Luke. You’ll see me a lot on the forum helping users and helping to keep order along with the help of my bro @Deadpool198!

You probably don’t wanna those boots you have equipped. Those have the lowest speed in the game. If you switch them, look for ones with good speed, but still with the other good attributes ur gonna need!

:fox_face::fox_face::fox_face:
-@Luke10

1 Like
#6

Despite being risky you can try using chain-lightning.
spells
bounceRange is 20, so watch if the first enemy near your target in this range isn’t a yak:
harrowland
and the code:

    if (enemy && enemy.health > 0) {
        var yak = enemy.findNearest(yaks);
        if ( enemy.distanceTo(yak) > 20 && hero.isReady('chain-lightning'))
            hero.cast('chain-lightning', enemy);
       // the code continues
   }
4 Likes
#7

Very smart! I’ve never thought of that.