I was trying to complete this level for 3 days but it seemed like im not experienced enought yet. But then i just changed one line of code that i should use according to Tips.
It says :
Some important things to note:
hero.findNearestMissiles() finds all missiles that they can see.
But hero.findNearestMissiles() its not working any way that i was trying to use it
After countless try i just changed it to
var NearestMissiles = hero.findNearest(projectiles);
So either im very stupid and cant understand the hero.findNearestMissiles() or either its not working and just missleading people(including me :P)
EDIT//
// NOT WORKING CODE
while(true) {
var friends = hero.findFriends();
// findEnemyMissiles finds all dangerous projectiles.
var projectiles = hero.findEnemyMissiles();
for(var i = 0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == "paladin") {
// Find the projectile nearest to the friend:
var NearestMissiles = hero.findNearestMissiles(projectiles);
if(NearestMissiles){
var distance = friend.distanceTo(NearestMissiles);
}
// If the projectile exists
// AND is closer than 10 meters to the paladin:
if(NearestMissiles&&distance<10){
// Command the friend to "shield":
hero.command(friend, "shield");
}
// ELSE, when there is no potential danger:
else {
// Advance the paladin:
hero.command(friend, "move", ({x:friend.pos.x+1,y:friend.pos.y}));
}
} else {
// If not a paladin, just advance:
if(friend.type != "paladin"){
hero.command(friend, "move", ({x:friend.pos.x+1,y:friend.pos.y}));
}
}
}
}