Zoo keeper javascript help

Can somebody help me with zoo keeper cs4?

My soldiers are not attacking

Here is my code

// Protect the cage.
// Put a soldier at each X.
var points = [];
points[0] = {x: 33, y: 42};
points[1] = {x: 47, y: 42};
points[2] = {x: 33, y: 26};
points[3] = {x: 47, y: 26};

// 1. Collect 80 gold.
while(hero.gold < 80) {
       var coin = hero.findNearestItem();
    if (coin) {
        var pos = coin.pos;
        var x = pos.x;
        var y = pos.y;
        hero.moveXY(x, y);  
    } 
}

// 2. Build 4 soldiers.
for(var i=0; i < 4; i++) {
    hero.summon("soldier");
}
// 3. Send your soldiers into position.

var friends = hero.findFriends();
for(var j=0; j < friends.length; j++) {
    var point = points[j];
    var friend = friends[j];
    var enemy = friend.findNearestEnemy();
    var distance = friend.distanceTo(enemy);
    
    if(enemy && enemy.team == "ogres" && distance < 5) {
        // Command friend to attack.
        hero.command(friend, "attack", enemy);
    } else {
        // Command friend to move to point.
        hero.command(friend, "move", point);
    }
}


I just solved it.

I just had to add a while true on send your soldiers to attack.

1 Like

If you could please mark something to close this topic, that would be great thank you :)

there should be a mark solution on each reply to this topic in the left corner. You can choose any reply that you want to be the solution


Somewhere around there

I would give you a screenshot however I don’t have any level help topics open for me…sorry about that

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.