Trying to scale uv coordinates depending on material

Hello! I am working on a mod for a game that just reads the name of the material of a face and then looks up the textures separately. Now I am creating a game world with large areas of rock, grass and so on. My problem is if I select for example an area of for example ground like for example here: it turns out like this here:

However what I want is it to look like this:

Since the world is pretty large it would be nice if I could do this automatically so that all faces of the grass material have this proper scale and all face of the rock material have their proper scale. Actually it would even be enough if I would be able to keep the relative size between model and UV-map so that the result is always sharp. I hope I expressed myself clearly. Thanks!