------------------------------------------------------------------------------------------------------------------------------------
function createGuardArmies()

	 PriestDef = LazyUnlimitedArmy:New({
		Player = 2,
		Area = 3500,
		AutoDestroyIfEmpty = true,
		TransitAttackMove = true,
		Formation = UnlimitedArmy.Formations.Chaotic,
		LeaderFormation = 4,
		AIActive = true,
		AutoRotateRange = 1000000,
		HiResJob = true
		},
		1,NumberOfUAs)
	PriestDef.CommandDelayer = 5
	
	guardpos = GetPosition("guards")
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderBow4, 8, guardpos, 3)
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderBow4, 8, guardpos, 3)
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderBow4, 8, guardpos, 3)
	
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderSword4, 8, guardpos, 3)
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderSword4, 8, guardpos, 3)
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderSword4, 8, guardpos, 3)
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderSword4, 8, guardpos, 3)
	
	PriestDef:CreateLeaderForArmy(Entities.PV_Cannon3, 0, guardpos, 3)
	PriestDef:CreateLeaderForArmy(Entities.PV_Cannon3, 0, guardpos, 3)
	PriestDef:CreateLeaderForArmy(Entities.PV_Cannon3, 0, guardpos, 3)
	
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderRifle1,4,guardpos,3)
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderRifle1,4,guardpos,3)
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderRifle1,4,guardpos,3)
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderRifle1,4,guardpos,3)
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderRifle1,4,guardpos,3)
	PriestDef:CreateLeaderForArmy(Entities.PU_LeaderRifle1,4,guardpos,3)
	
	PriestDef:AddCommandLuaFunc(DefendPriest,true)
 end

function DefendPriest(self)
		if self.CommandDelayer >= 0 then
			self.CommandDelayer = self.CommandDelayer -1
			return false
		else
			self.CommandDelayer = 5
		end
		if GetDistance(self:GetPosition(),guardpos) > 5000 then
			return false, UnlimitedArmy.CreateCommandFlee(guardpos)
		else
				return false, UnlimitedArmy.CreateCommandDefend(guardpos,5500)
		end
		return false
end
	