Mit dieser Funktion kann man testen ob mindestens ein Hauptmann einer Armee sich in der Nähe einer bestimmten Position befindet.
ArmyOne ist ein globales Armee-Table.
function ControlArmyOne() if Counter.Tick2("ControlArmyOne", 10) then if IsArmyNear(ArmyOne, "FeindlicheBurg") then FrontalAttack(ArmyOne) else Advance(ArmyOne) end end end
Der Parameter _Distance ist optional. Ohne ihn wird der Aktionsradius der Armee verwendet.
function IsArmyNear(_Army, _Target, _Distance) local LeaderID = 0 -- Distance not available? Then use the army's rodeLength if not _Distance then _Distance = _Army.rodeLength end -- Iterate over all leaders local NumberOfLeader = Logic.GetNumberOfLeader(_Army.player) for i = 1, NumberOfLeader do -- Get next leader ID LeaderID = Logic.GetNextLeader(_Army.player, LeaderID) -- Is the leader connected to this army? local ArmyID = AI.Entity_GetConnectedArmy(LeaderID) if ArmyID == _Army.id then -- Is this leader near the target position? if IsNear(LeaderID, _Target, _Distance) then -- At least one leader is near, that's enough return true end end end -- No leader is in range of the target return false end