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

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?

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.
:lion: :lion: :lion:

Here’s the code:

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

And here’s what gear I have (kinda OP, I know):
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.

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:

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!


1 Like

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

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

Very smart! I’ve never thought of that.