Remember, as in the other post, to work backwards from the type you need to ultimately use downstream. As @nhuurre says, if you need integers then work backwards from that and don’t store anything upstream in a matrix, but rather in an integer array.
However, in the weird case where you actually need to multiply/invert/decompose matrices in order to generate integers to be used for indexing exclusively in generated quantities or transformed data (where real-to-integer conversion won’t break the HMC sampler), then you could use the hacks discussed in the link below to accomplish what you need. However, once you reach that point I strongly suspect that it would be simpler to precompute the transformed data (e.g. in R or python) and pass them as data, or to post-compute the generated quantities (e.g. in R or python) from the fitted model object.