If the terrains have uniform file names like "t01.hmp", "t02.hmp" and so on, you can first identity if a clicked entity is a terrain via ent_type ( = 4 means it is a terrain). Then, you can use str_for_entfile or the ->type field of the ENTITY-struct to get the filename, e.g. "t01.hmp". If you use str_trunc(str, 4) and str_clip(str, 1), you only have then "01", which you can use together with str_to_int to get the numeric value (= 1).