Well, it's even simpler than that.That's the whole code; all that's left is to translate it from "Olbanian."Towns = array of towns;
xyzHero = hero's coordinates;
TargetTown = nil;
MinDistance = 999;
For i, town in towns
Distance = (xyzTown - xyzHero);
If Distance < MinDistance then
MinDistance = Distance
TargetTown = Town
End
End
I probably don't know "Olbanian" very well, but the translation into Lua should be decent.:)
function FindClosestEnemyTown()
local towns = GetObjectNamesByType('TOWN');
if IsHeroAlive('Avran') then
if GetHeroTown('Avran') then
return nil;
end;
else
return nil;
end;
local hx, hy, hz = GetObjectPosition('Avran');
local dist = {};
for i, town in towns do
local tx, ty, tz = GetObjectPosition(town);
if tz == hz then
local s = sqrt((tx - hx) * (tx - hx) + (ty - hy) * (ty - hy));
dist[town] = s;
end;
end;
local targetTown = min(dist);
if GetObjectOwner(targetTown) == GetObjectOwner('Avran') then
return nil;
else
return targetTown;
end;
end;
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога
Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4