Of the proper (by NWC) Heroes games, only III and IV allow some map scripting in their map editors. Mostly this uses events like "do something when a specific hero visits this castle".
Of what I consider fan games at best, I have only played V and it is much more mod-friendly but has its own range of problems some of which are hardware-related.Then again III had received extensive fan modifications over the years which, aside from various fan content that generally contradicts either the story or the broader world from Might and Magic games, have introduced lots and lots of bug fixes and quality of life improvements. I think "HD mod" is the one for most fixes with least arbitrary fan changes but I recommend to properly look into the subject of modern HMM3 modding instead of trusting my memories of what I read mostly years ago.